关于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/09/05 23:00:00
关于javascript中为firefox定义contain方法,这句while(obj!=null&&typeof(obj.tagName)!=
xS]OP+ C."mt7MYmS,a:0(&k6E2 cvi/ZㅻZB{Nyޏa=Ǩ>/1C!ZȊd-]i*Tx3FcqNI6;?QS$|Mf7^H RjȊց"}O%P% xQtq$_{rl|{=K . A  ?n/y[3ĕPcPTupn:~I,LFc#8$y0e4R`~DXS%62(S/!Ke ?D톺Uw-.n_%jAd}xM}hl6{Rq,{[?Q[:4[ǻ87nTV{Aa޺8+6)\rB@h8w.i-)dY ٳ?`}_jڀrT|MK1(Ϧ9O e!,&uI2[#

关于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 节点的解析.