-1

嗨,我有一个表格,当用户输入一个值时,它会附加一个表格,例如。如果用户输入“1”,则与“1”相关的值将附加到表上,并且该表将附加到我的页面上,但我什至调用了 jquery 的函数,该函数将在按下添加按钮时附加表行但是该功能不起作用是因为我是通过ajax生成按钮吗????任何人都可以帮助我吗

这是我生成新行的脚本

  $(document).ready(function() {
          var currentItem = $('#items').val();
                $('#addnew').click(function() {
          var strToAdd = '<tr><td align="center"><input type="text" size="6" maxlength="6" id="ord_' + currentItem + '" maxlength="6" name="ord_' + currentItem + '" class="form-input-oth" onkeyup="return copy(this.val());"/></td>\n\
                                        <td align="center"><input type="text" size="6" maxlength="6" id="srno' + currentItem + '" maxlength="6" name="srno_' + currentItem + '" class="form-input-oth"/></td>\n\
                                        <td align="center"><textarea name="descrip_' + currentItem + '" id="descrip_' + currentItem + '" cols="70" class="form-input-textarea"></textarea></td>\n\
                                        <td align="center"><input type="text" size="6" maxlength="9" id="unit_' + currentItem + '" maxlength="6" name="unit_' + currentItem + '" class="form-input-rate"/></td>\n\
                                        <td align="center"><input type="text" size="6" maxlength="9" id="rate_' + currentItem + '" maxlength="6" name="rate_' + currentItem + '" class="form-input-rate"/></td></tr>';
                     $('#data').append(strToAdd);
                       currentItem++;
                       $('#items').val(currentItem);

                });
            });

这是我从中调用 ajax 函数的文本框

<input type="text" size="6" maxlength="6" id="code" maxlength="6" name="quotno" value="<?php echo ($addflag == 0) ? $get['quotno'] : ""; ?>" class="form-input-code"  onblur="showyear('boqsrch.php?code='+this.value);"/>

这是我生成表的文件

<?php
require("includes/dbconnect.php");
include ('includes/function.php');

$code = trim($_GET["code"]);

$result = mysql_query("SELECT * FROM quotdtl WHERE vouchno='$code'") or die(mysql_error());

if (mysql_num_rows($result) > 0) {
    echo '<div style="margin-left: 400px; margin-right: auto;  width:180px;">
            <h2><font color="#0099FF"  face="Times New Roman">Bill Of Quotation</font></h2>
          </div>
          <hr/>
          ';
    echo "<table border=\"1px\" width=\"80%\" id=\"data\" align=\"center\">";
;?>

                  <tr>
                     <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Order</font><span></span></label></td>
                     <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Sr No.</font><span></span></label></td>
                     <td width="580px" align="center"><label for=""><font color="#0099FF" size="3px">Description</font><span></span></label></td>
                     <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Unit</font><span></span></label></td>
                     <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Rate</font><span></span></label></td>
                  </tr>

<?php

    $ctr = 0;
    while ($row = mysql_fetch_array($result)) {
        echo "<tr>";
        echo "<td align=\"center\"><input type=\"text\" size=\"6\" maxlength=\"6\" id=\"ord_$ctr\" maxlength=\"6\" name=\"ord_$ctr\" value=\"$row[orderby]\" class=\"form-input-oth\" onkeyup=\"document.getElementById('ord_$ctr').value = this.value;\"/></td>";
        echo "<td align=\"center\"><input type=\"h\" size=\"6\" maxlength=\"6\" id=\"srno_$ctr\" maxlength=\"6\" name=\"srno_$ctr\" value=\"$row[srno]\" class=\"form-input-oth\" onkeyup=\"document.getElementById('srno_$ctr').value = this.value;\"/></td>";
        echo "<td align=\"center\"><textarea name=\"descrip_$ctr\" cols=\"70\" class=\"form-input-textarea\" onkeyup=\"document.getElementById('descrip_$ctr').value = this.value;\">$row[descrip]</textarea></td>";
        echo "<td align=\"center\"><input type=\"text\" size=\"6\" maxlength=\"9\" id=\"unit_$ctr\" maxlength=\"6\" name=\"unit_$ctr\" value=\"$row[unit]\" class=\"form-input-rate\" onkeyup=\"document.getElementById('unit_$ctr').value = this.value;\"/></td> ";
        echo "<td align=\"center\"><input type=\"text\" size=\"6\" maxlength=\"9\" id=\"rate_$ctr\" maxlength=\"6\" name=\"rate_$ctr\" value=\"$row[rate]\" class=\"form-input-rate\" onkeyup=\"document.getElementById('rate_$ctr').value = this.value;\"/></td>";
        echo "</tr>";
        $ctr++;
    }
    echo '</table>';

} else {
    ?>
            <div style="margin-left: 400px; margin-right: auto;  width:180px;">
                <h2><font color="#0099FF"  face="Times New Roman">Bill Of Quotation</font></h2>
            </div>
            <hr/>
                 <table border="1px" width="80%" id="data" align="center">
                  <tr>
                      <td><br /></td>
                  </tr>

                  <tr>
                     <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Order</font><span></span></label></td>
                     <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Sr No.</font><span></span></label></td>
                     <td width="580px" align="center"><label for=""><font color="#0099FF" size="3px">Description</font><span></span></label></td>
                     <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Unit</font><span></span></label></td>
                     <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Rate</font><span></span></label></td>
                  </tr>
                  <tr>
                    <td align="center"><input type="text" size="6" maxlength="6" id="ord_0" maxlength="6" name="ord_0" value="" class="form-input-oth" onkeyup="document.getElementById('ord_0').value = this.value;"/></td> 
                    <td align="center"><input type="text" size="6" maxlength="6" id="srno_0" maxlength="6" name="srno_0" value="" class="form-input-oth" onkeyup="document.getElementById('srno_0').value = this.value;"  /></td> 
                    <td align="center"><textarea name="descrip_0" cols="20" class="form-input-textarea" onkeyup="document.getElementById('descrip_0').value = this.value;"></textarea></td>
                    <td align="center"><input type="text" size="6" maxlength="9" id="unit_0" maxlength="6" name="unit_0" value="" class="form-input-rate" onkeyup="document.getElementById('unit_0').value = this.value;"  /></td> 
                    <td align="center"><input type="text" size="6" maxlength="9" id="rate_0" maxlength="6" name="rate_0" value="" class="form-input-rate" onkeyup="document.getElementById('rate_0').value = this.value;"  /></td> 
                  </tr>
                  <tr>
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_1" value="" class="form-input-oth" onkeyup="document.getElementById('ord_1').value = this.value;"  /></td> 
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_1" value="" class="form-input-oth" onkeyup="document.getElementById('srno_1').value = this.value;"  /></td> 
                    <td align="center"><textarea name="descrip_1" cols="20" class="form-input-textarea" onkeyup="document.getElementById('descrip_1').value = this.value;"></textarea></td>
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_1" value="" class="form-input-rate" onkeyup="document.getElementById('unit_1').value = this.value;"  /></td> 
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_1" value="" class="form-input-rate" onkeyup="document.getElementById('rate_1').value = this.value;"  /></td> 
                  </tr>
                   <tr>
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_2" value="" class="form-input-oth" onkeyup="document.getElementById('ord_2').value = this.value;"  /></td> 
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_2" value="" class="form-input-oth" onkeyup="document.getElementById('srno_2').value = this.value;"  /></td> 
                    <td align="center"><textarea name="descrip_2" cols="20" class="form-input-textarea" onkeyup="document.getElementById('descrip_2').value = this.value;"/></textarea></td>
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_2" value="" class="form-input-rate" onkeyup="document.getElementById('unit_2').value = this.value;"  /></td> 
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_2" value="" class="form-input-rate" onkeyup="document.getElementById('rate_2').value = this.value;" /></td> 
                  </tr>
                  <tr>
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_3" value="" class="form-input-oth" onkeyup="document.getElementById('ord_3').value = this.value;"/></td> 
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_3" value="" class="form-input-oth" onkeyup="document.getElementById('srno_3').value = this.value;" /></td> 
                    <td align="center"><textarea name="descrip_3" cols="20" class="form-input-textarea" onkeyup="document.getElementById('descrip_3').value = this.value;"></textarea></td>
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_3" value="" class="form-input-rate" onkeyup="document.getElementById('unit_3').value = this.value;"/></td> 
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_3" value="" class="form-input-rate" onkeyup="document.getElementById('rate_3').value = this.value;"/></td> 
                  </tr>
                  <tr>
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_4" value="" class="form-input-oth"  onkeyup="document.getElementById('ord_4').value = this.value;"/></td> 
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_4" value="" class="form-input-oth"  onkeyup="document.getElementById('srno_4').value = this.value;" /></td> 
                    <td align="center"><textarea name="descrip_4" cols="20" class="form-input-textarea" onkeyup="document.getElementById('descrip_4').value = this.value;"></textarea></td>
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_4" value="" class="form-input-rate" onkeyup="document.getElementById('unit_4').value = this.value;"/></td> 
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_4" value="" class="form-input-rate" onkeyup="document.getElementById('rate_4').value = this.value;"  /></td> 
                  </tr>
                  <tr>
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_5" value="" class="form-input-oth" onkeyup="document.getElementById('ord_5').value = this.value;"/></td> 
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_5" value="" class="form-input-oth" onkeyup="document.getElementById('srno_5').value = this.value;"  /></td> 
                    <td align="center"><textarea name="descrip_5" cols="20" class="form-input-textarea" onkeyup="document.getElementById('descrip_5').value = this.value;"></textarea></td>
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_5" value="" class="form-input-rate" onkeyup="document.getElementById('unit_5').value = this.value;"/></td> 
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_5" value="" class="form-input-rate" onkeyup="document.getElementById('rate_5').value = this.value;"/></td> 
                  </tr>
                  <tr>
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_6" value="" class="form-input-oth" onkeyup="document.getElementById('ord_6').value = this.value;"/></td> 
                    <td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_6" value="" class="form-input-oth" onkeyup="document.getElementById('srno_6').value = this.value;"/></td> 
                    <td align="center"><textarea name="descrip_6" cols="20" class="form-input-textarea" onkeyup="document.getElementById('descrip_6').value = this.value;"></textarea></td>
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_6" value="" class="form-input-rate"  onkeyup="document.getElementById('unit_6').value = this.value;" /></td> 
                    <td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_6" value="" class="form-input-rate"  onkeyup="document.getElementById('rate_6').value = this.value;" /></td> 
                  </tr>
                  <?php }?>
            </table>

                         &nbsp;<input type="button" id="addnew" class="addnew" class="classname" name="addnew" value="+" /> 
                          <input type="hidden" id="items" name="items" value="7" />                 
4

2 回答 2

1

尝试使用on而不是click http://api.jquery.com/on/绑定点击事件

这将允许行为对匹配选择器的任何事件起作用,即使是在绑定发生之后发生的事件。

于 2013-05-21T07:10:37.167 回答
0

您应该使用以下内容:

// New way (jQuery 1.7+) - .on(events, selector, handler)
$('#container').on('click', '#inputButtonID', function(event) {
    event.preventDefault();
    alert('testlink'); 
});

这会将您的事件附加到#container元素内的任何输入,从而减少必须检查整个document元素树的范围并提高效率。

更多信息在这里:

于 2013-05-21T07:17:43.090 回答