日期:2014-05-16 浏览次数:20473 次
var id='123456'
var html = "<div data-id='"+id+"' class='Board wfc wft' style='position: absolute; left: "+new_pic_x+"px; top: "+new_pic_y+"px;'><a href='#' class='link x'><img src='http:\/\/img.hb.aicdn.com\/1b4344dca1732a9fcfbdb9f71263aaa8c8850dd834a2d-oMl40s_sq235' class='large'><div class='over '><h3>捧花的诱惑。<\/h3><h4><\/h4><div class='pin-count'>"+(pl_len+1).toString()+"<\/div></div></a><div class='FollowBoard2'><input type='checkbox' class='BoardAvatar' data-id='"+id+"'><span href='\/hiwedding\/' class='BoardUserUrl x'>花瓣婚庆<\/span><a data-id='"+id+"' href='#' class='follow btn wbtn'><strong>删除<\/strong><\/a><\/div>";
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function()
{
var aDiv=getElementByAttr('div','data-id','123456');//返回data-id为123456的div集合
for(var i=0;i<aDiv.length;i++)
aDiv[i].style.backgroundColor='#ccc';//
}
function getElementByAttr(tag,attr,value)
{
var aElements=document.getElementsByTagName(tag);
var aEle=[];
for(var i=0;i<aElements.length;i++)
{
if(aElements[i].getAttribute(attr)==value)
aEle.push( aElements[i] );
}
return aEle;
}
</script>
</head>
<body>
<div data-id="123456" class="box">测试</div>
<div data-id="123456" class="box">测试1</div>
</body>
</html>