日期:2014-05-16 浏览次数:20462 次
<div id="cke_88_contents" class="cke_contents cke_reset" role="presentation" style="height: 222px;">
<span id="cke_162" class="cke_voice_label">按 ALT+0 获得帮助</span>
<iframe src="" frameborder="0" class="cke_wysiwyg_frame cke_reset" style="width: 100%; height: 100%;" title="所见即所得编辑器, textareafield-1156-inputEl" aria-describedby="cke_162" tabindex="0" allowtransparency="true"></iframe>
</div>
<body>
<div class = "aa" role = "aa">1</div>
<div class = "aaa" role = "aaa">2</div>
<div class = "aaaa" role = "abc">3</div>
<div class = "aa" role = "abc">4</div>
<div class = "aaa" role = "bbb">5</div>
<div class = "aaaa" role = "cba">6</div>
</body>
<script>
function get(ele,className,role){
var allEle = document.getElementsByTagName(ele),
eleClass = "",
eleRole = "",
reg = null;
for(var i=0,len = allEle.length;i<len;i++){
eleClass = allEle[i].className;
eleRole = allEle[i].getAttribute("role");
reg = new RegExp("(^\s*
------解决方案--------------------
\s+)"+className+"($\s*
------解决方案--------------------
\s+)")
if(reg.test(eleClass) && eleRole == role){
return allEle[i];
}
}
return null;
}
console.log(get("div","aaa","bbb").innerHTML);