IE在这个脚本中找到的错误在哪里?

时间:2010-07-15 13:53:00

标签: javascript internet-explorer object

IE继续在倒数第二行给出一个错误,指出“需要对象”。我不确定问题出在哪里。有什么建议吗?

function showdiv()
{
  document.getElementById("dialogue").style.display = "";
  document.getElementById("screen").style.display = "";
  document.getElementById("screen").style.width = getBrowserWidth();
}
function hidediv(opt){
if(opt=="agree"){
  document.Annexation.checkbox.checked = true;
  document.getElementById("dialogue").style.display = "none";
  document.getElementById("dialogue").style.display = "none";
  document.getElementById("screen").style.display = "none";
}else{
  document.getElementById("dialogue").style.display = "none";
  document.getElementById("screen").style.display = "none";
}}

window.onscroll = scrollEvent;
function scrollEvent() {
var y;
if (document.documentElement && !document.documentElement.scrollTop)
  // IE6 +4.01 but no scrolling going on
  y=document.documentElement.scrollTop; 
else if (document.documentElement && document.documentElement.scrollTop){
  // IE6 +4.01 and user has scrolled
  y=document.documentElement.scrollTop;
}
else if (document.body && document.body.scrollTop){
  // IE5 or DTD 3.2
  y=document.body.scrollTop;
}
  document.getElementById("screen").style.top = y+"px";
} 

3 个答案:

答案 0 :(得分:1)

以下其中一项可能会返回null:

document.getElementById("dialogue")
document.getElementById("screen")
document.Annexation
document.Annexation.checkbox

getBrowserWidth未定义。

答案 1 :(得分:0)

document.getElementById("screen")未定义。添加以下代码:

if( !document.getElementById("screen") ) alert( "Spara was right." );

它会告诉你是否是这种情况。

答案 2 :(得分:0)

document.Annexation.checkbox.checked = true;

中的附件标准是什么?

您有2种方法可以选择复选框。一个是为复选框的标签指定名称值。

<input type="checkbox"  name="ck" />

document.getElementsByName("ck")[0].checked = true;选中复选框。

另一种方法是为复选框的标记分配id。

<input type="checkbox"  id="ck" />

document.getElementById("ck").checked = true;选中复选框。