标签:dcl i++ function amp jquer add reg jquery tag
/*1 jquery*/
document.ready(function(){
$("div .poem-stanza").addClass(‘ highlight‘)
}
)
/*2 DOM*/
window.onload = function(){
var divs = document.getElementsByClassName(‘poem-stanza‘);
for (var i=0;i<divs.length;i++){
divs[i].className += ‘ highlight‘;
}
}
/*3 DOM+RegExp*/
window.onload = function(){
var divs = document.getElementsByTagName(‘div‘);
for (var i=0;i<divs.length;i++){
if(hasClass("poem-stanza",divs[i])
&& !hasClass("highlight",divs[i])){
divs[i].className += ‘ highlight‘;
}}
}
function hasClass(cls,elemts){
var findclass = new RegExp (""+ cls +"");
return findclass.test(elemts.className);
}
标签:dcl i++ function amp jquer add reg jquery tag
原文地址:http://www.cnblogs.com/xinfangzhang/p/6682050.html