http://www.scriptlover.com/pages/article.asp?ArticleID=219

解决方案 »

  1.   

    不知道该怎么搞呀
    把changeColor放到addOnClick事件里不行吗?友情顶一下啦
      

  2.   

    当然了,你在一个bothOperation中前后对tr对象的onclick事件进行了三次赋值.
    当然只有最后一次的赋值会有效了.
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <title>Untitled Document</title>
            <script>
                var row = null;
                //动态获得单击行号并传给deleteRow();insertRow(); 
                function addOnClick(){
                    for (var j = 0; j < document.getElementById("detail").rows.length; j++) {
                        document.getElementById("detail").rows[j].onclick = showRowIndex;
                    }
                }
                
                function showRowIndex(){
                    rowIIdex = this.sectionRowIndex;
                    var trs = document.getElementById("detail").getElementsByTagName("tr");
                    
                    for (var j = 0; j < trs.length; j++) {
                        if (trs[j] == this) {
                            this.style.backgroundColor = "green";
                            row = j;
    continue;
                        }
                        trs[j].style.backgroundColor = "#FFFFFF";
                    }
                }
                
                
                //删除行
                function deleteRow(rowNum){
                    if (rowNum < 0) 
                        return;

                    document.getElementById("detail").deleteRow(rowNum);
                }
                
                function bothOperation(){
                    addOnClick();
                }
            </script>
        </head>
        <body oncontextmenu="event.returnValue=false;" onload="bothOperation();">
            <input type="button" value="delete" onclick="deleteRow(row)">
            <table border="1" id="detail">
                <tr>
                    <td>
                        111
                    </td>
                </tr>
                <tr id="detail">
                    <td>
                        111
                    </td>
                </tr>
                <tr id="detail">
                    <td>
                        111
                    </td>
                </tr>
                <tr id="detail">
                    <td>
                        111
                    </td>
                </tr>
                <tr id="detail">
                    <td>
                        111
                    </td>
                </tr>
            </table>
        </body>
        <script language="JavaScript">
        </script>
    </html>
      

  4.   

    后一个事件会覆盖前一个的
    这样试试
    function addOnClick() { 
    for(var j=0;j <9;j++){ 
    //document.getElementById("detail").rows[j].onclick  = showRowIndex; 

    } function showRowIndex() { 
    rowIIdex = this.sectionRowIndex; 
    } //点击后行变色 
    function changeColor() { 
    var trs = document.getElementById("detail").getElementsByTagName("tr"); 
    addOnClick(); 
    for(var i=0; i <trs.length; i++) { 
    trs[i].onclick=function(){
    showRowIndex.call(this);
    for(var j=0;j <trs.length;j++){ 
    trs[j].style.backgroundColor = "#FFFFFF"; 

    this.style.backgroundColor = "green"; 


    } //删除行 
    function deleteRow(rowNum) { 
    detail.deleteRow(rowNum); 
    } function bothOperation() { 
    //addOnClick(); 
    changeColor(); 
    }
      

  5.   

    <input tepy="button" onclick="bt()">
    function bt(){
       bt01();
       bt02();
    }
    function bt01(){}
    function bt02(){}
      

  6.   


    对,就是这样。调用a,a中调用b,c即可。
      

  7.   

    addOnClick写在changeColor里或者changeColor写在addOnClick里