Javascript 如何隐藏窗体并仅在选中时显示?
我想建立我的第一个程序。昨天我开始编码,我无法停止,但我在Javascript 如何隐藏窗体并仅在选中时显示?,javascript,jquery,html,forms,debugging,Javascript,Jquery,Html,Forms,Debugging,我想建立我的第一个程序。昨天我开始编码,我无法停止,但我在onchange函数方面遇到了问题。我希望仅在我的选项列表中选择了方形时显示。其他列表也是如此。我还没有做他们的表格,因为我被卡在了squareA 这是我的密码 <script> function myShapes() { var a1 = document.getElementById("shapes").value; if(a1.value == option.value) { docume
onchange
函数方面遇到了问题。我希望
仅在我的选项列表中选择了方形时显示。其他列表也是如此。我还没有做他们的表格,因为我被卡在了squareA
这是我的密码
<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>
函数myShapes(){
var a1=document.getElementById(“形状”).value;
如果(a1.value==选项.value){
document.getElementById(“square”).value=(“squareA”);
}否则{
document.getElementById(“square”).disabled=true;
}
}
}
计算尺寸
选择形状
广场
矩形
合二为一
皮带
梯形
通过
在长行中是无效或错误的代码。您需要调用
onchange
属性中的函数,然后检查更改处理程序中的值并设置表单的显示值
函数myShapes(){
/*更改时,检查select的值,并根据它将display css值设置为none或block*/
document.getElementById('squareA')。style.display=document.getElementById('shapes')。value=='Square'?'block':'none'
}
计算尺寸
选择形状
广场
矩形
合二为一
皮带
梯形
通过
您需要在更改时调用该函数,如onchange=“myShapes()”
您是否正在使用jQuery库进行pageno sir。。标签上有建议我还有什么错误,先生?