var $container = documentgetElementById('container');
var $ul = $containergetElementsByTagName('ul');
// 要取的class
var className = 'col';
var ulCollection = [];
for (var i = 0; i < $ullength; i += 1) {
var ul = $ul[i],
classList = ulclassNamesplit(' ');
for (var j = 0; j < classListlength; j += 1) {
if (className === classList[j]) {
ulCollectionpush(ul);
break;
}
}
}
consolelog(ulCollection);
代码 请收下~~~~
<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 = documentgetElementsByClassName('okdog');
for(var i=0;i<reslength;i++){
res[i]addEventListener('click',function(e){
alert(esrcElementinnerHTML)
},false);
}
</script>
</body>
var oUl=documentgetElementsByTagName("ul")[0];
alert(oUlclassName);
这个应该是所有浏览器都支持
function getByClass(oParent, sClass) { //根据class获取元素
var oReasult = [];
var oEle = oParentgetElementsByTagName("");
for (i = 0; i < oElelength; i++) {
if (oEle[i]className == sClass) {
oReasultpush(oEle[i])
}
};
return oReasult;
}
以上就是关于js取值class全部的内容,包括:js取值class、js获取class对象的值、js中如何获取class值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)