你好,请问该如何在onclick里写条件语句?有什么办法?

<script language="javascript">
function tanchuan()
{
if(center.style.display=="none")
{
center.style.display="block"
}
else
{
center.style.display="none"
}
}
</script>

这段代码在onclick=""里怎么写?
我的HTML代码是这样的
<div id="top" onclick="">
</div>
<div id="center" style="display:none;">
</div>
我想用上面DIV控制下面DIV的显示和隐藏

一只萌萌小番薯
浏览 302回答 3
3回答

慕容3067478

需要准备的材料分别有:电脑、html编辑器、浏览器。1、首先,打开html编辑器,新建html文件,例如:index.html,编写问题基础代码。2、将index.html的<button>标签中的onclick属性调整为:onclick="tanchuan()"。3、浏览器运行index.html页面,此时点击btn按钮就会执行tanchuan()函数中的条件语句了。
打开App,查看更多内容
随时随地看视频慕课网APP