我正在嘗試使用jQuery更新表單輸入的值。這是我的HTML:使用jQuery更新輸入值的屬性
<div class="form-group">
<label for="fb-updateDefaultValue">Default Value</label>
<input type="text" class="form-control" id="fb-updateDefaultValue">
</div>
這裏是我的jQuery:
var currentDefaultValue = formElement.find('input').attr('value');
alert(currentDefaultValue); //This is just used to verify my code is working. This line does successfully alert the value in the input attribute
$("#fb-updateDefaultValue").val(currentDefaultValue); //This line is not updating the value attribute of the input even though the alert has the correct value
出於某種原因$("#fb-updateDefaultValue").val(currentDefaultValue);
不工作。有什麼建議麼?
您設置的值相同! – sbaglieri 2015-01-26 21:07:44
@sbaglieri我知道,我試圖將一個輸入字段的當前值設置爲另一個。 – three3 2015-01-26 21:10:20
'Val'用於輸入。標籤不是輸入。改用'text'代替。 – 2015-01-26 21:10:48