我想構建我的第一個程序。昨天我開始編碼,我不能停下來,但我在onchange
函數中遇到了問題。我只想在我的選項列表上選擇Square時才顯示<form id="squareA">
。另一個列表也一樣。我還沒有完成他們的形式,因爲我被卡在方塊A。如何隱藏表單並僅在選擇時顯示?
這是我的代碼。
<script>
function myShapes() {
var a1 = document.getElementById("shapes").value;
if(a1.value == option.value) {
document.getElementById("square").value = ("squareA");
} else {
document.getElementById("square").disabled = true;
}
}
}
</script>
<legend>Calculate Dimension</legend>
<select id="shapes" onchange="myShapes">
<option selected="selected" value="none">Select Shape</option>
<option onselect="mySquare" id="square" value="Square">Square</option>
<option onselect="myRect" id="rect" value="Rectangle">Rectangle</option>
<option onselect="myComb" id="comb" value="Combined">Combined</option>
<option onselect="myStrap" id="strap" value="Strap">Strap</option>
<option onselect="myTrap" id="trap" value="Trapezoidal">Trapezoidal</option>
</select>
<form id="squareA">
<div disabled="disabled" id="disa">
<input id="squareD" type="text" placeholder="Dimension"/> by
<input id="squareD2" type="text" placeholder="Dimension"/>
</div>
</form>
</fieldset>
在長行內部是沒有工作或錯誤的代碼。
您需要在調用函數改變像'onchange =「myShapes()」' –
你使用jQuery庫的頁面 –
沒有先生..它建議在標籤列表.. –