zoukankan      html  css  js  c++  java
  • js 动态增加/删除表格行

    <table id="friend_comment-table" width="80%" >
    <tr>
    <td class="label">网友点评:</td>
    <td>
    <a href="#" onclick="addLadder(this,'friend_comment-table')"><strong>[+]</strong></a>

    <table>
    <tr>
    <td>
    <textarea name="friend_desc[]" cols="85" rows="6">tre</textarea>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>

    <script language="JavaScript">
    <!--

    var Browser = new Object();

    Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
    Browser.isIE = window.ActiveXObject ? true : false;
    Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1);
    Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1);
    Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1);

    /**
    * 新增一个价格阶梯
    */
    function addLadder(obj,table_obj, amount, price)
    {

    var src = obj.parentNode.parentNode;

    var idx = rowindex(src);
    var tbl = document.getElementById(table_obj);
    var row = tbl.insertRow(idx + 1);
    var cell = row.insertCell(-1);
    cell.innerHTML = '';
    var cell = row.insertCell(-1);
    cell.innerHTML = src.cells[1].innerHTML.replace(/(.*)(addLadder)(.*)(\[)(\+)/i, "$1removeLadder$3$4-");;
    }

    /**
    * 删除一个价格阶梯
    */
    function removeLadder(obj,table_obj){

    var row = rowindex(obj.parentNode.parentNode);
    var tbl = document.getElementById(table_obj);

    tbl.deleteRow(row);
    }

    function rowindex(tr){
      if (Browser.isIE){
        return tr.rowIndex; //针对IE
      }else{
        table = tr.parentNode.parentNode;
        for (i = 0; i < table.rows.length; i ++ ){
          if (table.rows[i] == tr){
            return i;
          }
        }
      }
    }
    //-->

    </script>

  • 相关阅读:
    杭电2074
    关于大整数n!的问题!
    杭电2053
    大整数乘法(高精度)
    JS:获取框架内容
    JQ:hover延迟效果
    jQ+Ajax+PHP 简单实例
    js节省document.getElementById("xxx")的方法
    QQ一键登录功能的实现过程
    点击文字出现文本框
  • 原文地址:https://www.cnblogs.com/taek/p/2345471.html
Copyright © 2011-2022 走看看