js封装方法
function getByClass(parent, tagname, classname) { / var aEls = parent.getElementsByTagName(tagname); var arr = []; var re = new RegExp('(^|\\s)' + classname + '(\\s|$)'); for (var i = 0; i < aEls.length; i++) { if (re.test(aEls[i].className)) { arr.push(aEls[i]); } } return arr; } function addClass(obj, sClass) { var aClass = obj.className.split(' '); if (!obj.className) { obj.className = sClass; return; } for (var i = 0; i < aClass.length; i++) { if (aClass[i] === sClass) return; } obj.className += ' ' + sClass; } function removeClass(obj, sClass) { var aClass = obj.className.split(' '); if (!obj.className) return; for (var i = 0; i < aClass.length; i++) { if (aClass[i] === sClass) { aClass.splice(i, 1); obj.className = aClass.join(' '); break; } } }