<div class="htmlarea"> <textarea id="runcode65145"> <meta http-equiv="Content-Type" content="text/html; charsetGB2312"> <title>判断li是否有样式_www.jb51.net </title> <style type="text/css"> .myli{ color:red; } </style> <script language="JavaScript" type="text/javascript"> window.onload = function(){ var ul = document.getElementById("myul"); var lis = ul.getElementsByTagName("li"); for(var i = 0; i < lis.length;i++){ if(lis[i].className == ""){ lis[i].className = "myli"; } } } </script> <ul id="myul"> <li>A</li> <li class="myli">B</li> <li>C</li> </ul> </textarea><br><input onclick="runEx('runcode65145')" type="button" value="运行代码"> <input onclick="doCopy('runcode65145')" type="button" value="复制代码"> <input onclick="doSave(runcode65145)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>