关于javascript中为firefox定义contain方法,这句while(obj!=null&&typeof(obj.tagName)!="undefind",疑问if(typeof(HTMLElement)!="undefined")//给firefox定义contains()方法,ie下不起作用\x09\x09{ \x09\x09 HTMLElement.prototype.contains=fu
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/29 22:45:48
![关于javascript中为firefox定义contain方法,这句while(obj!=null&&typeof(obj.tagName)!=](/uploads/image/z/14547913-25-3.jpg?t=%E5%85%B3%E4%BA%8Ejavascript%E4%B8%AD%E4%B8%BAfirefox%E5%AE%9A%E4%B9%89contain%E6%96%B9%E6%B3%95%2C%E8%BF%99%E5%8F%A5while%28obj%21%3Dnull%26%26typeof%28obj.tagName%29%21%3D%22undefind%22%2C%E7%96%91%E9%97%AEif%28typeof%28HTMLElement%29%21%3D%22undefined%22%29%2F%2F%E7%BB%99firefox%E5%AE%9A%E4%B9%89contains%28%29%E6%96%B9%E6%B3%95%2Cie%E4%B8%8B%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%5Cx09%5Cx09%7B+%5Cx09%5Cx09+HTMLElement.prototype.contains%3Dfu)
关于javascript中为firefox定义contain方法,这句while(obj!=null&&typeof(obj.tagName)!="undefind",疑问if(typeof(HTMLElement)!="undefined")//给firefox定义contains()方法,ie下不起作用\x09\x09{ \x09\x09 HTMLElement.prototype.contains=fu
关于javascript中为firefox定义contain方法,这句while(obj!=null&&typeof(obj.tagName)!="undefind",疑问
if(typeof(HTMLElement)!="undefined")//给firefox定义contains()方法,ie下不起作用
\x09\x09{
\x09\x09 HTMLElement.prototype.contains=function (obj)
\x09\x09 {
\x09\x09\x09 while(obj!=null&&typeof(obj.tagName)!="undefind"){//
\x09 if(obj==this) return true;
\x09 \x09 obj=obj.parentNode;
\x09 \x09 }
\x09\x09\x09 return false;
\x09\x09 }
\x09}
以上是定义contain方法,while(obj!=null&&typeof(obj.tagName)!="undefind"不是判断obj是否存在么,为什么还要加typeof(obj.tagName)!="undefind",这个不多余么?
关于javascript中为firefox定义contain方法,这句while(obj!=null&&typeof(obj.tagName)!="undefind",疑问if(typeof(HTMLElement)!="undefined")//给firefox定义contains()方法,ie下不起作用\x09\x09{ \x09\x09 HTMLElement.prototype.contains=fu
在Firefox中节点间存在一个空节点(有可能是文本节点text-Node).空节点不具有节点名称,但却存在于文档的节点集合中.所以多数情况下判断tagName还是很重要的.具体情况你可以查看w3c中关于DOM 节点的解析.