小弟又来讨教了。。
貌似出现了喝昨天问题不一样的东西
例子很简单:
页面代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新窗口打开一个页面</title>
<script type="text/javascript" src="http://s.syyx.com/nycs/js/jquery-1.4.2.min.js"></script>
<script src="script/script07.js" language="javascript" type="text/javascript" </script>
</head><body bgcolor="#FFFFFF">
<div align="center">
<h1>Let's Play the Windows</h1>
<h2>
<a href="#" id="openWin"> open a new window </a>
<br/>
<a href="#" id="closeWin">close a new window</a>
</h2>
</div></body>
</html>script07.js中的JS代码// JavaScript Document
window.onlaod=newWinLinks;
var newWindow=null;
alert(document.links.length);
function newWinLinks()
{
for (var i=0;i<document.links.length;i++)
{
document.links[i].onclick=chgWindowState;
alert("111111");
}
}function windowOpen()
{
if(newWindow && ! newWindow.closed)
{
return true;
}
return false;
}function chgWindowState()
{
if(this.id == "closeWin")
{
if(windowOpen())
{
newWindow.close();
}
else
{
alert("This window is already open!");
}
}
if(this.id == "openWin")
{
if(windowOpen())
{
alert("The window is already open");
}
else
{
newWindow = window.open("","newWin","toolbar,location=yes,width=300,height=200");
}
}
return false;
}现在的效果是 显示links数是0 应该是2的
自然也就没有进入alert("11111");这里
小弟 觉得是dom文档没有加载完全的原因
因为小弟在html文档末位添加
alert(document.links.length);明显显示的2
问下 怎么解决JS 判断DOM文档加载完毕以后才执行JS代码啊
貌似出现了喝昨天问题不一样的东西
例子很简单:
页面代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新窗口打开一个页面</title>
<script type="text/javascript" src="http://s.syyx.com/nycs/js/jquery-1.4.2.min.js"></script>
<script src="script/script07.js" language="javascript" type="text/javascript" </script>
</head><body bgcolor="#FFFFFF">
<div align="center">
<h1>Let's Play the Windows</h1>
<h2>
<a href="#" id="openWin"> open a new window </a>
<br/>
<a href="#" id="closeWin">close a new window</a>
</h2>
</div></body>
</html>script07.js中的JS代码// JavaScript Document
window.onlaod=newWinLinks;
var newWindow=null;
alert(document.links.length);
function newWinLinks()
{
for (var i=0;i<document.links.length;i++)
{
document.links[i].onclick=chgWindowState;
alert("111111");
}
}function windowOpen()
{
if(newWindow && ! newWindow.closed)
{
return true;
}
return false;
}function chgWindowState()
{
if(this.id == "closeWin")
{
if(windowOpen())
{
newWindow.close();
}
else
{
alert("This window is already open!");
}
}
if(this.id == "openWin")
{
if(windowOpen())
{
alert("The window is already open");
}
else
{
newWindow = window.open("","newWin","toolbar,location=yes,width=300,height=200");
}
}
return false;
}现在的效果是 显示links数是0 应该是2的
自然也就没有进入alert("11111");这里
小弟 觉得是dom文档没有加载完全的原因
因为小弟在html文档末位添加
alert(document.links.length);明显显示的2
问下 怎么解决JS 判断DOM文档加载完毕以后才执行JS代码啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货