for(var i=0i<obj.lengthi++)
{
if(obj[i].className == 'a')//找出span标记中class=a的那个标记
{
var getObj = obj[i]
value = getObj.innerHTML//获得他的innerHTML
}
}//有效且管用,但是很笨的方法,目前我没发现还有其他方法。
<html><head>
<meta
http-equiv="Content-type"
content="text/html
charset=utf-8">
<title>1</title>
</head>
<script
type="text/javascript"
charset="utf-8">
window.onload=function()
{
document.getElementsByClassName('aaa')[0].innerHTML="sdf"
}
</script>
<body>
<div
class="aaa">
</div>
</body>
</html>
是getElementsByClassName,你少个s
firefox、Opera浏览器下测试通过
代码 请收下~~~~
<body><span class="okdog" lay-id="user1">1只狗</span><span class="okdog" lay-id="user2">2只狗</span><span class="okdog" lay-id="user3">3只狗</span><span class="okdog" lay-id="user4">4只狗</span><span class="okdog" lay-id="user5">5只狗</span>
<div id="showdog">输出结果</div>
<script>
var res = document.getElementsByClassName('okdog')
for(var i=0i<res.lengthi++){
res[i].addEventListener('click',function(e){
alert(e.srcElement.innerHTML)
},false)
}
</script>
</body>