闲来无事,JS排序

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<style>
B
{    border:1PX SOLID gray;}
</style>
</HEAD>
<BODY>
<button onclick="ok();">插我</button>
<id=aaa style='border'>5</B>


<SCRIPT LANGUAGE=javascript>

 
function ok()
 
{
    
    
var b_tag=document.getElementsByTagName("B");
    
var x=parseInt(10 * Math.random());
    
    
if(b_tag.length>0)
    
{
        
var b_length=b_tag.length;
        
var flag=false;
        
for(var i=0;i<b_length;i++)
        
{    
            
if(x<parseInt(b_tag[i].innerText))
            
{
                
            }

            
else
            
{
                 b_tag[i].insertAdjacentHTML(
"beforeBegin","<B>"+x+"</B>");
                 flag
=true;
                 
break;
            }

            
        }

        
if(!flag)
        
{
            b_tag[b_length
-1].insertAdjacentHTML("afterEnd","<B>"+x+"</B>");
        }

    }

    
else
    
{
         aaa.insertAdjacentHTML(
"afterEnd","<B>"+x+"</B>");
    }

 }

 
</SCRIPT>

</BODY>
</HTML>

posted on 2007-10-20 08:53  小子好黑  阅读(427)  评论(1编辑  收藏  举报

导航