我有一个通过此链接激活的浮动图层:
<a href="javascript:ToggleFloatingLayer('FloatingLayer',1);"> BUTTON </a>
这是浮动层:
<div id="FloatingLayer">
<div id="closeX"> <a href="#" onClick="ToggleFloatingLayer('FloatingLayer',0);return false">x</a>
</div>
剧本:
<script language="JavaScript1.2">
function ToggleFloatingLayer(DivID, iState) // 1 visible, 0 hidden
{
if(document.layers) //NN4+
{
document.layers[DivID].visibility = iState ? "show" : "hide";
}
else if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById(DivID);
obj.style.visibility = iState ? "visible" : "hidden";
}
else if(document.all) // IE 4
{
document.all[DivID].style.visibility = iState ? "visible" : "hidden";
}
}
</script>
我想要&#34; BUTTON&#34;打开并关闭此浮动图层。所以它在同一个链接中打开和关闭。但是现在我只能通过&#34; closeX&#34; X。我该怎么办?
答案 0 :(得分:2)
jQuery是标准的跨浏览器和功能丰富的JavaScript库 在您的应用程序中学习和使用jQuery是所有业务应用程序中最好的 以下是api和倾斜网站的链接
代码段在您的下方
<!DOCTYPE html>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
function toggleFloatingLayer(divID) {
$("#" + divID).toggle();//its only single line to manage toggling for all browsers
}
</script>
</head>
<body>
<a href="#" onclick="toggleFloatingLayer('FloatingLayer')"> BUTTON </a>
<div id="FloatingLayer" style="display:none;border:solid 2px silver;">
<div id="closeX" style="background:#efefef"> <a href="#" onClick="toggleFloatingLayer('FloatingLayer')">x</a>
</div>
<div>
Test content of Floating layer
</div>
</div>
</body>
</html>