javascript显示风格的问题 [英] a problem at javascript display style
本文介绍了javascript显示风格的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<body>
<div id="topic" onclick="showTopic()">Topic 1</div>
<ul id="sub" style="display:none"><li>Sub topic 1</li><li>Sub topic 2</li><li>Sub topic 3</li></ul>
<script>
function showTopic() {
var e=document.getElementById("sub");
if ( e.style.display=""){
e.style.display="none";
}
else{
e.style.display="";
}
}
</script>
</body>
</html>
为什么我无法隐藏子再次点击主题1的话题?
为你的帮助提供帮助
why I can not hide the sub topic when click the Topic 1 again?
Thaks for your help
推荐答案
嗨史蒂文
试试这样..
对于比较值,你需要使用==而不是= ...
以下代码将切换subid标签..显示/隐藏操作..
Hi Steven
Try like this..
For comparing values u need to use "==" instead of "=" ...
the below code will toggle the "sub" id tag.. show/hide operation..
function showTopic() {
var e = document.getElementById("sub");
if (e.style.display == "block") {
e.style.display = "none";
}
else {
e.style.display = "block";
}
}
这篇关于javascript显示风格的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文