<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="one">我是one</div>
<div class="wrap">
<div class="one">我也是one</div>
<div class="two">我也two</div>
<div class="one">i'm one too</div>
</div>
<script>
function selectorClass(className) {
if (className.indexOf('.') === 0) {
className = className.slice(1);
}
return document.getElementsByClassName(className);
}
var oneObjArr = selectorClass('.one');
console.log(oneObjArr);
for (var i in oneObjArr) {
oneObjArr[i].innerHTML = '我们都是one'
}
</script>
</body>
</html>