输入字段在设定值后延伸?

时间:2017-06-19 12:18:39

标签: javascript jquery html

在我的应用程序中,我有几个表单,用户可以选择值,该值将显示在文本输入字段中。这些值通常是一到三个字符。一旦我选择了值,我的输入字段就会扩展(改变宽度)。输入字段有足够的空间(大小设置为10),没有理由进行扩展。我已经检查过我的值是否被修剪,并且没有任何奇怪的值。我想知道这是否与我使用的JQuery .val()或其他东西有关?这是我的代码示例。

HTML:

<div class="formItem">
    <label for="status">Status:</label>
    <input type="text" name="status" id="status" value="" data-master="SS_STATUS" size="10" maxlength="10" readonly />
    <img src="Images/add.png" alt="Click to add value" class="masterRecords" />
</div>

JQuery的:

//Looping through the table with the records where users choose desired code/value for their input field
$('#searchTbl tbody tr').on('click', function(){
    var codeVal = $.trim($(this).find('td:eq(0)').text()); //Here I grab the value from the table
    $('#status').val(codeVal).css('font-weight','bold'); //Here input field is populated
});

我附加了图像,您可以在用户选择值之前和之后看到输入字段。场大小有明显差异。 HTML结构中没有任何变化(我在设置值后在我的开发工具中进行了监控)。

Input Field

1 个答案:

答案 0 :(得分:1)

如果我更正,您不仅要设置一个值,还应用一种风格:.css('font-weight','bold');,我怀疑这是您更改输入的原因#39;宽度......

尝试将此调用移至.css()进行检查,如果确认,请尝试在呈现页面时应用您的样式...

相关问题