为什么document.getElementById("id")总是为null? 我在页面创建了元素标签,也设了id 按理来说应该直接能找到,可试了好几次都是返回Null 怎么回事? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是不是前面没写form的名字啊,把代码帖出来啊 document.getElementById("formname:id");一般这样就对了 <SCRIPT LANGUAGE="JavaScript">function makepopup(url,width,height,overflow){ if(width>640){width=640}; if(height>480){height=480}; if(overflow=""||!/^scroll|resize|both$/.test(overflow)) { overflow="both"; } var win=window.open(url,'','width='+width+',height='+height+',scrollbars='+(/^scroll|resize|both$/.test(overflow)?'yes':'no')+',status=yes,toolbar=no,menubar=no,location=no'); return win; } document.getElementById("survey").onclick=function()//就是这行 { var survey=makepopup(this.href,640,480,"scroll"); return survey.closed }</SCRIPT><BODY> <a href="http://www.baidu.com" id="survey">www.baidu.com</a>//我设这个id</BODY> document.getElementById("survey").onclick=function()//就是这行{var survey=makepopup(this.href,640,480,"scroll");return survey.closed}=>window.onload = function(){document.getElementById("survey").onclick=function()//就是这行{var survey=makepopup(this.href,640,480,"scroll");return survey.closed}}; <a href="http://www.baidu.com" id="survey">www.baidu.com</a>放到 你的javascript前面也可以 document.getElementById("survey").onclick=function()//就是这行折行先于<a href="http://www.baidu.com" id="survey">www.baidu.com</a>//我设这个id执行,肯定是找不到dom元素了,最简单的方法是把js放到这行之后,或者用其他机制,确保dom载入了再执行上面的js代码 Dom没有加载完 你就去getElementById肯定是null了 cj205的可以 你也可以将那个function写在body标签的onload事件中 图片如何实现判断高度调整自适应全屏 hover 和 click 冲突,怎么样才能使触发click事件时 hover不触发 JS 如何控制UL左右移动 document.write的问题 怎样删除网页中指定“ID”的 的内容呀? jquery双击<td>里面内容变成select框 为什么不显示 替换后的内容??? 请问引号的嵌套用法???? 如何在JAVASCRIPT里写生成不同的表格的背景颜色 修改Ext JS 2中GridPanel的边框颜色 中文数字的正则表达式与书写规则 DIV和BODY的滚过条问题
一般这样就对了
<SCRIPT LANGUAGE="JavaScript">
function makepopup(url,width,height,overflow)
{
if(width>640){width=640};
if(height>480){height=480};
if(overflow=""||!/^scroll|resize|both$/.test(overflow))
{
overflow="both";
}
var win=window.open(url,'','width='+width+',height='+height+',scrollbars='+(/^scroll|resize|both$/.test(overflow)?'yes':'no')+',status=yes,toolbar=no,menubar=no,location=no');
return win;
}
document.getElementById("survey").onclick=function()//就是这行
{
var survey=makepopup(this.href,640,480,"scroll");
return survey.closed
}
</SCRIPT>
<BODY>
<a href="http://www.baidu.com" id="survey">www.baidu.com</a>//我设这个id</BODY>
{
var survey=makepopup(this.href,640,480,"scroll");
return survey.closed
}=>window.onload = function(){
document.getElementById("survey").onclick=function()//就是这行
{
var survey=makepopup(this.href,640,480,"scroll");
return survey.closed
}};
折行先于
<a href="http://www.baidu.com" id="survey">www.baidu.com</a>//我设这个id
执行,肯定是找不到dom元素了,最简单的方法是把js放到这行之后,或者用其他机制,确保dom载入了再执行上面的js代码
cj205的可以 你也可以将那个function写在body标签的onload事件中