日期:2014-05-17  浏览次数:20772 次

在javaScript中怎么给全部的span标记设置颜色
在javaScript中给全部的span标记设置颜色,没有id
------解决方案--------------------
用Jquery,这个是隐藏所有<p>的例子,改改就行了
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>

<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button type="button">Click me</button>
</body>
</html> 
------解决方案--------------------
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
   var size= document.getElementsByTagName("span");
for(var o in size){
document.getElementsByTagName("span")[o].style.backgroundColor='red';
}
   
});
</script>
</head>
<body>
<span>全部</span>
<p>r,我d会434消失。</p>
<p>点击我,er消d失。</p>
<span>54545</span>
<p>也要点击我哦。</p>
<span>全部dwewe</span>

</body>
</html>