1.javascript中 class属性获取 如下代码在IE8以上、、google等浏览器测试正常
var sp = document.getElementsByTagName('span'); for (var i = 0; i < sp.length; i++) { if (question_TagImages[i].getAttribute('class') == 'mytest') { sp[i].onclick = function () {...} } }
2.如果在IE6的版本下,则不能获取calss属性,应该使用className来获取,
var sp = document.getElementsByTagName('span'); for (var i = 0; i < sp.length; i++) { if (question_TagImages[i].getAttribute('className') == 'mytest') { sp[i].onclick = function () {...} } }
3.为了兼容其它浏览器,可以使用name属性进行元素选择,在IE6以上,Google等浏览器测试正常。
var sp = document.getElementsByTagName('span'); for (var i = 0; i < sp.length; i++) { if (question_TagImages[i].getAttribute('name') == 'mytest') { sp[i].onclick = function () {...} } }