【问题标题】:Append row in table using XAJAX - values are deleted使用 XAJAX 在表中追加行 - 值被删除
【发布时间】:2013-01-03 09:49:32
【问题描述】:

我有这张 HTML 表格:

<table style="width: 100%;" class="allBorders">
    <tbody id="added_articles">
        <tr id="header_articles">
            <td>test</td>
            <td>&nbsp;</td>
        </tr>
    </tbody>
</table>

并使用 XAJAX 我像这样追加新的 ROW

function addNewLine()
{
    global $objResponse;
    $uniqueID = time();
    $return = "<tr id='articles_".$uniqueID."'>";
    $return .= "<td><input type='text' id='v_$uniqueID' name='v[]' /></td>";
    $return .= "</tr>";
    $objResponse->append("added_articles", "innerHTML", $return);
    return $objResponse;
}

每当我添加新行时,之前添加的行中的所有值都会被清除..

例子:

  1. 添加第一行
  2. 第一行的值设置为“TEST”
  3. 添加第二行,删除第一行的值.. .

有什么想法吗?

【问题讨论】:

    标签: html-table row xajax


    【解决方案1】:
    <div id="added_articles">
        <table style="width: 100%;" class="allBorders">
            <tbody>
                <tr id="header_articles">
                    <td>test</td>
                    <td>&nbsp;</td>`enter code here`
                </tr>
            </tbody>
        </table>
    </div>
    
    function addNewLine()
    {
        global $objResponse;
        $return .= "<table style="width: 100%;" class="allBorders">";
        $return .= "<tr id='articles_".$uniqueID."'>";
            $return .= "<td><input type='text' id='v_$uniqueID' name='v[]' /></td>";
        $return .= "</tr></table>";
        $objResponse->append("added_articles", "innerHTML", $return);
            return $objResponse;
    }
    

    【讨论】:

      【解决方案2】:

      我在使用此函数添加“tr”时遇到了问题。

      我使用的代码是..

       function Start($oid){
         $objResponse = new xajaxResponse();
         $userauth = Authorizer::getUserByID($oid); // I Save here DB rows return.
            while ( $rows = $userauth->fetchRow() ){
                $row[] = $rows['uid'];
      
              $userInfo = User::userInfo($rows['uid']);
         $useradd .= '              <tr class="spaceunder">
                                       <td>'. $rows['uid'] .'</td>
                                       <td>'. $rows['status'] .'</td>
                                       <td>'. $rows['perm'] .'</td>
                                       <td>'. $rows['dtauth'] .'</td>    
                                    </tr>';
      
              $objResponse->addAlert($useradd);
              $objResponse->addAssign('userAdded', 'innerHTML', $useradd);
      
               return $objResponse->getXML();
           }
      

      而我的 HTML 是...

          <table id ="userAdded" border="0" cellpadding="0" cellspacing="0" style="width:100%;height:100%;padding:5px 0px 0 0px;margin:0px 0px 0 0px;">
                      <tr valign="top" style="height:37px;padding:1px 1px 1 1px;margin:0px 0px 0 0px;"> 
                         <td align="left">
                            <table width="100%" cellspacing="0" cellpadding="0" border="0">
      
      
      
                            </table>
                         </td>
                      </tr>
                  </table>'
      

      而且效果很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-17
        • 2016-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-24
        相关资源
        最近更新 更多