• table指定位置添加行


    <html> 
    <head> 
    <script type="text/javascript"> 
    //global var 
    var pos =0 
    //to find the position you mouse has pressed 
    function whichElement(e) 
    { 
    var targ 
    if (!e) var e = window.event 
    if (e.target) targ = e.target 
    else if (e.srcElement) targ = e.srcElement 
    if (targ.nodeType == 3) // defeat Safari bug 
    targ = targ.parentNode 
    if(targ.tagName=="TD"){//to adjust whether the element is tabledata 
    pos = targ.parentNode.rowIndex+1 
    } 
    else if(targ.tagName=="INPUT"){ 
    //to do nothing 
    } else{ 
    pos =0 
    } 
    //alert(pos) 
    } 
    //to insert a row in the place 
    function insRow() 
    { 
    //alert(pos) 
    var x=document.getElementById('myTable').insertRow(pos) 
    var y=x.insertCell(0) 
    var z=x.insertCell(1) 
    y.innerHTML=document.getElementById("cell1").value 
    z.innerHTML=document.getElementById("cell2").value 
    } 
    </script> 
    </head> 
    <body onmousedown="whichElement(event)"> 
    <table id="myTable" border="1"> 
    <tr> 
    <td>Row1 cell1</td> 
    <td>Row1 cell2</td> 
    </tr> 
    <tr> 
    <td>Row2 cell1</td> 
    <td>Row2 cell2</td> 
    </tr> 
    <tr> 
    <td>Row3 cell1</td> 
    <td>Row3 cell2</td> 
    </tr> 
    </table> 
    
     
    <p> 
    Cell1:<input type="text" id= "cell1" value="cell1"/> 
    Cell2:<input type="text" id= "cell2" value="cell2"/> 
    </p> 
    <input type="button" onclick="insRow()" value="插入行"> 
    </body> 
    </html>

    欢迎评论。。。。让我看到你的反馈。。。。

  • 相关阅读:
    php中获取各种路径
    大型网站系统架构演化之路
    404、500、502等HTTP状态码介绍
    Linux 查看进程和删除进程
    mysql中FIND_IN_SET的使用方法
    PHP导出Excel 数字末尾变0或小数点解决办法
    PHP API接口测试小工具
    要慎用mysql的enum字段的原因
    mysql 导入&导出sql文件
    Linux下php安装memcache扩展
  • 原文地址:https://www.cnblogs.com/rzm2wxm/p/5624095.html
Copyright © 2020-2023  润新知