我想我的JavaScript有问题。不管我怎么尝试,它基本上都不起作用。
我有一个非常简单的脚本:
<div id="simplediv" style="background-color:yellow;border:1px solid black;display:none;width:200px;height:200px;">Click anywhere in the document to auto-close me</div>
<a href="#" onclick="Popup.show('simplediv');return false;">Click Here</a>在这个网站上,它是有效的:http://www.javascripttoolbox.com/lib/popup/example.php
但是当我把它添加到我自己的页面时:
<head>
<title>Script</title>
</head>
<body>
<div id="simplediv" style="background-color:yellow;border:1px solid black;display:none;width:200px;height:200px;">Click anywhere in the document to auto-close me</div>
<a href="#" onclick="Popup.show('simplediv');return false;">Click Here To Show DIV</a>
</body>恐怕行不通。我也尝试过在标签中使用其他javascript代码,它们在我获取它的网站上都能正常工作,我不知道为什么它现在不能工作。
有人知道它为什么会这样吗?
发布于 2013-12-30 05:40:02
如上所述,onclick="“弹出函数没有定义;您的浏览器不知道该函数应该做什么。
您可以根据需要进行编辑,但在标题中放入如下内容将定义您的函数:
<script type="text/javascript">
function showDiv(div_id){
document.getElementById(div_id).style.visibility="visible";
}
function hideDiv(div_id){
document.getElementById(div_id).style.visibility="hidden";
}
</script>然后,您可以使用所需的参数在onclick="“事件中调用这些函数。类似于以下内容:
<a href="#" onclick="hideDiv('simplediv');">Click Here To Hide DIV</a>
<a href="#" onclick="showDiv('simplediv');">Click Here To Show DIV</a>https://stackoverflow.com/questions/20829487
复制相似问题