以下是代码片段: !--StartFragment--script language="JavaScript" !-- /* * 要显示某个层时调用HideElements(oDiv) * 隐藏某个层时调用ShowElements() */ /* * 隐藏下拉框函数 */ function HideElements(el) { if (!window
以下是代码片段:
<!--
/*
* 要显示某个层时调用HideElements(oDiv)
* 隐藏某个层时调用ShowElements()
*/
/*
* 隐藏下拉框函数
*/
function HideElements(el)
{
if (!window.__temp__) window.__temp__ = new Array();
var o = ["select","iframe","applet","object"];
for (var i=0; i<o.length; i++)
{
var elms = document.getElementsByTagName(o[i]);
for (var j=0; j<elms.length; j++)
{
var p = getPosition(elms[j]);
var e = getPosition(el);
if (e.left + e.width > p.left && e.left < p.left + p.width &&
e.top + e.height > p.top && e.top < p.top + p.height)
{
window.__temp__[j] = elms[j];
elms[j].style.visibility = "hidden";
}
}
}
function getPosition(el)
{
var e = el.offsetParent, x = el.offsetLeft, y = el.offsetTop;
while (e.tagName != 'BODY')
{
x += e.offsetLeft;
y += e.offsetTop;
e = e.offsetParent;
}
return {
"left": x,
"top": y,
"width": el.offsetWidth,
"height": el.offsetHeight
}
};
};
/*
* 显示下拉框
*/
function ShowElements()
{
var t = window.__temp__;
if (t) {
for (var i=0; i<t.length; i++)
{
t[i].style.visibility = "visible";
}
}
};
//-->
</script>
以下是代码片段:
<div id="demo" style="position:absolute;width:100;height:100;z-index:9999;visibility:hidden"></div>
<select style="width:150px"><option>see me ?</option></select>
<script language="JavaScript">
<!--
var i=0;
var ie = document.all ? 1 : 0;
var o = document.getElementById("demo");
var w = o.offsetWidth;
var h = o.offsetHeight;
if (ie)
o.innerHTML = '<iframe name="WebFrame" frameborder=0 width="' + w +
'" height="' + h + '" marginwidth=0 marginheight=0></iframe>';
function show()
{
var str = '<div style="border:1px solid;width:' + w + 'px;height=' + h + 'px">hello</div>'
if (ie) {
var doc = window.frames["WebFrame"].document;
doc.open();
doc.write('<html><head></head><body>' + str + '</body></html>');
doc.close();
} else {
o.innerHTML = str;
}
o.style.visibility = ++i%2 ? 'visible' : 'hidden';
};
//-->
</script>
以下是代码片段:
<!--
var oPopup = window.createPopup();
oPopup.document.body.innerHTML = 'New Window';
oPopup.show(100, 100, 200, 200, oPopup.document);
/*
* window.createPopup产生的窗口可以跨载框架,更不用说下拉框了,但其使用有一定的限制,并不推荐使用
*/
//-->
</script>