Php中不能使用Jquery字段


Could Not Jquery field in Php

我创建了一个添加项页面,其中我使用jquery实现了自动完成文本框和自动乘法。当我使用自动完成文本框乘法不能工作。我的Jquery代码是....

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
 <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.autocomplete.js"></script>
<script>
 $(document).ready(function(){
  $(".product").autocomplete("autocomplete1.php", {
        selectFirst: true
  });
  $(".brand").autocomplete("autocomplete2.php", {
        selectFirst: true
  });
  $(".model").autocomplete("autocomplete3.php", {
        selectFirst: true
  });
 });
</script>-->
<script  type="text/javascript">
$(document).ready(function() {
                            $(".product").autocomplete("autocomplete1.php", {
        selectFirst: true
  });
  $(".brand").autocomplete("autocomplete2.php", {
        selectFirst: true
  });
  $(".model").autocomplete("autocomplete3.php", {
        selectFirst: true
  });
    $('#dataTable').on('keyup', '.price', calTotal)
                  .on('keyup', '.quantity', calTotal);
// find the value and calculate it
    function calTotal() {
        var $row = $(this).closest('tr'),
            price    = $row.find('.price').val(),
            quantity = $row.find('.quantity').val(),
            total    = price * quantity;
// change the value in total
        $row.find('.txt').val(total)
    }
});
</script>

我的html代码是…

<TABLE id="dataTable" class="dataTable" width="350px" border="1">
       <tr> <th></th>     
        <th width="144"><div align="center"><strong>Product Name</strong></div></th>
        <th width="146"><div align="center"><strong>Brand Name</strong></div></th>
        <th width="146"><div align="center"><strong>Model No</strong></div></th>
        <th width="146"><div align="center"><strong>Dealer Price</strong> (DP)</div></th>
        <th width="146"><div align="center"><strong>Quantity (Q)</strong></div></th>
        <th width="146"><div align="center"> <strong>Total Price</strong> (TP)        </div>
          <div align="center">
            (TP = DP x Q)
</div>
        </th>
        <th width="153"><div align="center"><strong>Description</strong></div></th> 

      </tr>
      <tbody>
        <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand" class="brand" /></td>
          <td><input type="text" name="model[]" id="model"  class="model" /></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
        <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand" class="brand" /></td>
          <td><input type="text" name="model[]" id="model"  class="model" /></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
        <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand" class="brand" /></td>
          <td><input type="text" name="model[]" id="model"   class="model"/></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
     <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand"  class="brand"/></td>
          <td><input type="text" name="model[]" id="model"   class="model"/></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
         <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand" class="brand" /></td>
          <td><input type="text" name="model[]" id="model"  class="model" /></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
        <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand" class="brand" /></td>
          <td><input type="text" name="model[]" id="model"  class="model" /></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
         <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand" class="brand" /></td>
          <td><input type="text" name="model[]" id="model"  class="model" /></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
        <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand" class="brand" /></td>
          <td><input type="text" name="model[]" id="model"  class="model" /></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
        <tr>
          <TD><INPUT type="checkbox" name="chk[]"/></TD>
          <td><input type="text" name="product[]" id="product" class="product" /></td>
          <td><input type="text" name="brand[]" id="brand" class="brand" /></td>
          <td><input type="text" name="model[]" id="model"  class="model" /></td>
          <td><input type="text" name="dprice[]" class="price"/></td>
          <td><input type="text" name="quantity[]" class="quantity"/></td>
          <td><input name="txt[]" type="text" class="txt" id="txt" /></td>
          <td><input type="text" name="quality[]" id="quality"/></td>

        </tr>
    </tbody>
  </TABLE>
<input type="button" value="Add Row" onClick="addRow('dataTable')" />
<input type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
<table width="1206" border="0">
  <tr>
    <td width="753">&nbsp;</td>
        <td width="124"><input name="btn" type="button" id="btn" value="Grand Total"/></td>
    <td width="315"><input type="text" id="sum" name="sum" onKeyUp="calculate();" /></td>
</tr>
 <tr>
    <td>&nbsp;</td>
    <!--<td colspan="2">Transport Price:  
    &nbsp; &nbsp; &nbsp;<input type="text" name="transport" id="transport" onKeyUp="calculate();" /></td>
  </tr>
   <tr>
    <td>&nbsp;</td>
    <td colspan="2">Grand Total: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="text" name="grandt" id="grandt" /></td>
  </tr>-->
</table>

我该怎么做

请帮助! !

如果您使用的是文本框,并且想要查看输入是否被更改,请使用:

$('#your-text-box').on('input', function() {
    //Do your calculation
    //Show it in your other textbox perhaps?
}