[已解决问题]
解决于 2008-07-12 14:21
<SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">ul </SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="tt"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">111 </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">111 </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">111 </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">111 </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">ul</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR>Object.prototype.Each </SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> </SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">function</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">(fun) {<BR> </SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">if</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">(</SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">this</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">.length </SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&&</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">
问题补充:
<ul id="tt">
<li>111 </li>
<li>111 </li>
<li>111 </li>
<li>111 </li>
</ul>
<script>
Object.prototype.Each = function(fun) {
if(this.length && this.length > 0){
for (var i = 0; i < this.length; i++)
fun(this[i], i);
}
}
var objs = document.getElementById("tt").getElementsByTagName("li");
objs.Each(function(obj, index){
alert(index);
})
</script>