我的代碼是在這裏http://jsfiddle.net/2BcS3/jQuery的選擇值開關上更改默認
$("#b").click(function(){
//should output: [user selection] - []
alert("[" + $("#s").val() + "] - [" + $("#i").val() + "]");
$("#i").val('nice');
//should output: [user selection] - [nice]
alert("[" + $("#s").val() + "] - [" + $("#i").val() + "]");
//should output: [nice] - [nice]
$("#s").val($("#i").val());
alert("[" + $("#s").val() + "] - [" + $("#i").val() + "]");
});
和HTML
<select id='s'>
<option value='0'>select</option>
<option value='1'>ok</option>
<option value='2'>no</option>
</select>
<input id='i' type='hidden' />
<button type='button' id='b'>go</button>
,你會發現這個問題的時候了。我正在嘗試將選擇的值更改爲動態輸入到隱藏字段中的值。出於某種原因,select不會獲取新值並自動切換到選擇列表的第一個值!
'我'沒有價值,你怎麼設'S'? – DevlshOne
s是通過選擇並在您點擊按鈕後進行更改來設置的,當您單擊該按鈕時我將被設置。檢查jsfiddle – Kal
但'i'是一個字符串和'S'有可選值0,1,2 – DevlshOne