我的朋友downvote後,我已在覈心Java腳本在這裏添加代碼:
<html>
<head>
<style>
span{display:block;}
</style>
<script type="text/javascript">
function getElementsByNoClassName() {
var node = document.getElementsByTagName("span");
console.log(node.length);
var a = [];
for (var i = 0, j = node.length; i < j; i++){
if (node[i].className=='')
node[i].setAttribute("style","color:red;");
}
}
window.onload=getElementsByNoClassName;
</script>
</head>
<body>
Content with No class is colored in red.
<span>0m2abBrL+RIHOEA+dZS+OqV3St+nJ/</span>
<wbr></wbr>
<span class="word_break"></span>
<span>zwq73Gfz8MQGB0yS++lfufSOV133huE</span>
<wbr></wbr>
<span class="word_break"></span>
vCB0s5D9w
<span class="text_exposed_hide">...</span>
</body>
</html>
這可以用jQuery的也可以做:
<html>
<head>
<style>
span{display:block;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("span").filter(
function(){
return $(this).attr('class')==undefined
}).css('color','red');
});
</script>
</head>
<body>
Content with No class is colored in red.
<span>0m2abBrL+RIHOEA+dZS+OqV3St+nJ/</span>
<wbr></wbr>
<span class="word_break"></span>
<span>zwq73Gfz8MQGB0yS++lfufSOV133huE</span>
<wbr></wbr>
<span class="word_break"></span>
vCB0s5D9w
<span class="text_exposed_hide">...</span>
</body>
</html>
你想要這純JavaScript或jQuery可以是一個選項? – 2012-01-18 05:49:09
我想要它純粹的javascript – vaichidrewar 2012-01-18 05:50:39
嗨,我在Java腳本中也添加了代碼 – 2012-01-18 06:21:36