為什么這樣寫 用getAttribute()得不到nodeName屬性?var arr=document.getElementsByTagName("li"); document.write(arr[0].getAttribute(nodeName));
為什么這樣寫 用getAttribute()得不到nodeName屬性?var arr=document.getElementsByTagName("li"); ? ? document.write(arr[0].getAttribute(nodeName));
2016-03-25
1,getAttribute()是用來獲取屬性值的,nodeName是標(biāo)簽名,不是屬性,
2、標(biāo)簽的屬性常見的有id,name,type等,
3、自定義屬性也是可以的,比如<p abc="123"><p>里面的abc就是自定義的屬性
4、getAttribute("abc")可以得到屬性值123,但是不能這樣寫getAttribute(abc),
但是可以這樣,abc="abc";getAttribute(abc);因為不加引號代表的是變量