js的一个选项卡,js的代码是什么意思?特别是三元运算符那个?
<scripttype="text/javascript"><!--functionsetTab(name,cursel,n){for(i=1;i<=n;i++){var...
<script type="text/javascript">
<!--
function setTab(name,cursel,n)
{
for(i=1;i<=n;i++)
{
var menu=document.getElementById(name+i);
if(menu)
{
var con=document.getElementById("con_"+name+"_"+i);
menu.className = (i==cursel?"hover":"");
con.style.display = (i==cursel?"block":"none");
}
}
}
//-->
</script>
</head>
<body>
<div id="indexnewsTab1">
<div class="newMenubox">
<ul>
<li id="newstag1" onmouseover="setTab('newstag',1,3)">国内新闻</li>
<li id="newstag2" class="hover" onmouseover="setTab('newstag',2,3)">国际新闻</li>
<li id="newstag3" onmouseover="setTab('newstag',3,3)">行业热点</li>
</ul>
</div>
<div class="newContentbox">
<div style="display: none" id="con_newstag_1" class="newtaglist">1</div>
<div style="display: block" id="con_newstag_2" class="newtaglist">2</div>
<div style="display: none" id="con_newstag_3" class="newtaglist">3</div>
</div>
</div> 展开
<!--
function setTab(name,cursel,n)
{
for(i=1;i<=n;i++)
{
var menu=document.getElementById(name+i);
if(menu)
{
var con=document.getElementById("con_"+name+"_"+i);
menu.className = (i==cursel?"hover":"");
con.style.display = (i==cursel?"block":"none");
}
}
}
//-->
</script>
</head>
<body>
<div id="indexnewsTab1">
<div class="newMenubox">
<ul>
<li id="newstag1" onmouseover="setTab('newstag',1,3)">国内新闻</li>
<li id="newstag2" class="hover" onmouseover="setTab('newstag',2,3)">国际新闻</li>
<li id="newstag3" onmouseover="setTab('newstag',3,3)">行业热点</li>
</ul>
</div>
<div class="newContentbox">
<div style="display: none" id="con_newstag_1" class="newtaglist">1</div>
<div style="display: block" id="con_newstag_2" class="newtaglist">2</div>
<div style="display: none" id="con_newstag_3" class="newtaglist">3</div>
</div>
</div> 展开
展开全部
menu.className = (i==cursel?"hover":"");
con.style.display = (i==cursel?"block":"none");
三元运算:
i==cursel?"hover":"";//如果i等于cursel,那么className为"hover",如果不等于则为"".
i==cursel?"block":"none");//一样的道理!如果i等于cursel,那么con的显示方式为"block" 否则为"none"
(表达式?成立:不成立)
con.style.display = (i==cursel?"block":"none");
三元运算:
i==cursel?"hover":"";//如果i等于cursel,那么className为"hover",如果不等于则为"".
i==cursel?"block":"none");//一样的道理!如果i等于cursel,那么con的显示方式为"block" 否则为"none"
(表达式?成立:不成立)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询