我想根据下拉值显示段落和输入文本。 我写下面的代码,但它不适合我。 输入文本永远不会正确显示或隐藏。
<html>
<script type="text/javascript">
function nameChange(){
var a = document.getElementById("shape").value;
if(a=="Circle"){
document.getElementById("geometry").innerHTML = "Please provide Radius of Circle: ";
document.getElementById("geometry1").style.display = "none";
document.getElementById("Input1").style.visibility = "visible";
}else if(a=="Triangle"){
document.getElementById("geometry").innerHTML = "Please provide Dimension of Triangle: ";
document.getElementById("geometry1").style.visibility = "hidden";
document.getElementById("Input1").style.visibility = "visible";
}else if(a=="Square"){
document.getElementById("geometry").innerHTML = "Please provide Dimension of Square: ";
document.getElementById("geometry1").style.visibility = "hidden";
document.getElementById("Input1").style.visibility = "visible";
}else{
document.getElementById("geometry").innerHTML = "Please provide Length of Rectangle: ";
document.getElementById("geometry1").innerHTML = "Please provide Breath of Rectangle: ";
document.getElementById("Input1").style.visibility = "visible";
document.getElementById("Input2").style.visibility = "visible";
}
}
</script>
<select id="shape" onChange="nameChange()">
<option value="Triangle">Triangle</option>
<option value="Rectangle">Rectangle</option>
<option value="Circle">Circle</option>
<option value="Square">Square</option>
</select>
<p id="geometry" /p>
<input id="Input1" type="text" stype="display:none">
<p id="geometry1" /p>
<input id="Input2" type="text" stype="display:none">
</html>
答案 0 :(得分:1)
试试这段代码吧。有多个拼写错误&amp;段落标签未正确关闭。
JS代码:
<select id="shape" onChange="nameChange()">
<option value="Triangle">Triangle</option>
<option value="Rectangle">Rectangle</option>
<option value="Circle">Circle</option>
<option value="Square">Square</option>
</select>
<p id="geometry"></p>
<input id="Input1" type="text" style="display:none">
<p id="geometry1"></p>
<input id="Input2" type="text" style="display:none">
HTML代码
int target = 10; // Or whatever
int count = myList.Count(x => x == target);