0
我有2個選擇列表mySelect和mySelect2。 如果點擊複選框選中其中一個,則另一個同時改變。jQuery,一旦值被存儲在新的部分,禁用輸入
請檢查下面的代碼:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function displayResult() {
if(document.form1.billingtoo.checked == true) {
var x = document.getElementById("mySelect").selectedIndex;
// Set selected index for mySelect2
document.getElementById("mySelect2").selectedIndex = x;
}
}
</script>
</head>
<body>
<form name="form1">
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br>
<input type="checkbox" name="billingtoo" onclick="displayResult()">
<br>
Select your favorite fruit 2:
<select id="mySelect2">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
</body>
</html>
...我怎麼禁用(變灰)mySelect2所以,你不能做任何修改,一旦值的任何變化都到位?
謝謝。
我怎麼會再次啓用,如果沒有選中該複選框使用JS的版本? – avidaicu 2012-08-09 04:25:10
正如我上面所說的,將'disabled'屬性設置回'false':'document.getElementById(「mySelect2」)。disabled = false;' – nnnnnn 2012-08-09 04:45:43