如何隐藏临时列表项并重新出现切换按钮后?当有一个隐藏的项目时,可以找到它的id?
function action(x) {
var parag = document.getElementById("li" + x);
if(parag.style.visibility = "hidden"){
parag.style.visibility = "visible";
}else{
parag.style.visibility = "hidden";
}
}
要么使用以下不起作用?
<head>
<script type="text/javascript">
function action(x){
var parag=document.getElementById("li"+x);
if(parag.style.display=="none"){
parag.style.display="block";
}else{
parag.style.display="none";
}
}
</script>
</head>
<body>
<ul>
<li id="li1">Item1</li>
<li id="li2">Item2</li>
<li id="li3">Item3</li>
</ul>
<form name="myform"><input type="button" onclick="alert(document.myform.select.value);action(document.myform.select.value)" value="show/hide"/><label>
<select name="select" id="select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</label></form>
</body>
</html>
答案 0 :(得分:0)
第一个代码中有错误:
if(parag.style.visibility="hidden"){
应该是
if(parag.style.visibility=="hidden"){
,否则parag.style.visibility
将始终设置为hidden
,表达式始终评估为true
。