JavaScript错误 - 无法设置未定义或空引用的属性'zIndex' [英] JavaScript Error - Unable to set property 'zIndex' of undefined or null reference

查看:402
本文介绍了JavaScript错误 - 无法设置未定义或空引用的属性'zIndex'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码适用于IE8,但不适用于较新的浏览器。

This code works with IE8 but not newer browsers.

var isNav, isIE
var coll = ""
var styleObj = ""

var zIndex = 2  // Must be larger than our backgrounds

if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape") {
    isNav = true
  } else {
    isIE = true
    coll = "all."
    styleObj = ".style"
  }
}

function show(obj) {
  obj.visibility = "visible"
}

function hide(obj) {
  obj.visibility = "hidden"
}

function changeVisibility(Obj,num) {
  var imgobj = eval('document.' + coll + 'image' + num + styleObj)
  
  // If it's one of our backgrounds we don't want to change its
  // zIndex
  //if (num > 22) {
  // if (Obj.checked)
  //    show(imgobj)
  //  else
  //    hide(imgobj)
  // return
  //}
  if (Obj.checked) {
    zIndex++
    setZIndex(imgobj, zIndex)
    show(imgobj)
  } else {
    hide(imgobj)
    zIndex--
  }
}

function setZIndex(obj, zOrder) {
  obj.zIndex = zOrder
}

function openWin(url, name) {
  popupWin = window.open(url, name, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=350,height=120');
}

function openBWin(url) {
 popupWin = window.open(url);
}

推荐答案

这意味着

That means that
var imgobj = eval('document.' + coll + 'image' + num + styleObj) 



返回null。你需要找出原因。我的理解是eval是邪恶的所以我建议改为使用jQuery


is returning null. You'll need to figure out why that is. My understanding is eval is evil so I would suggest changing to using jQuery


(#fieldName)或document.getElementById(id);而不是使用eval。
("#fieldName") or document.getElementById("id"); instead of using eval.


这篇关于JavaScript错误 - 无法设置未定义或空引用的属性'zIndex'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆