Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 值数组的onblur函数_Javascript - Fatal编程技术网

Javascript 值数组的onblur函数

Javascript 值数组的onblur函数,javascript,Javascript,这是我的全部代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> body { backgrou

这是我的全部代码

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">

   <head>
 <style>
    body  {
   background-image:url("rice.png");
  }
  </style>
   <script type="text/javascript" src="js/script.js"></script> 
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />



  <link rel='stylesheet' type='text/css' href='css/style.css' />
  <link rel='stylesheet' type='text/css' href='css/print.css' media="print" 
/>
  <script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
   <script type='text/javascript' src='js/example.js'></script>
   </head>

    <body>
     <form name="form1" method="post" class="register" action="<?php echo 
     $_SERVER['PHP_SELF'];?>" >

     <div id="page-wrap">

      <textarea id="header">PURCHASE</textarea>

       <div id="identity">

         <textarea id="address" disabled>AR Traders  Address:
        </textarea >

        <div id="logo">

          <div id="logoctr">
            <a href="javascript:;" id="change-logo" title="Change    
 ">Change Logo</a>
            <a href="javascript:;" id="save-logo" title="Save 
        changes">Save</a>
            |
            <a href="javascript:;" id="delete-logo" title="Delete 
       logo">Delete Logo</a>
            <a href="javascript:;" id="cancel-logo" title="Cancel changes">Cancel</a>
          </div>

          <div id="logohelp">
            <input id="imageloc" type="text" size="50" value="" /><br />
            (max width: 540px, max height: 100px)
          </div>
          <img id="image" src="images/logo.png" alt="logo" />
        </div>

    </div>

    <div style="clear:both"></div>

    <div id="customer">
     <br>
        <textarea id="customer-title">Widget Corp.
        c/o Steve Widget</textarea>

        <table id="meta">
            <tr>
                <td class="meta-head">Invoice #</td>
                <td><textarea name="invoice"></textarea></td>
            </tr>
            <tr>

                <td class="meta-head">Date</td>
                <td><input type="date" name="date" /><br></td>
            </tr>


        </table>

       < /div>


     <fieldset class="row2">
            <legend>Product Details</legend>
            <p> 
                <input type="button" value="Add Product" 
        onClick="addRow('dataTable')" /> 
                <input type="button" value="Remove Product" 
      onClick="deleteRow('dataTable')"  /> 

            </p><br>
           <table id="dataTable" class="form" border="1">
              <tbody>
                <tr class="j">
                  <p>
                    <td><input type="checkbox" required="required" 
      name="chk[]" checked="checked" /></td>
                    <td>
                        <label>Product Details</label>
                        <input type="text" required="required" 
    name="product[]">
                     </td>
                     <td>
                        <label for="brand">Brand</label>
                        <input type="text" class="small"  name="brand[]">
                     </td>
                     <td>
                        <label for="s_brand">Sub Brand</label>
                        <input type="text" required="required" class="small"  
 name="s_brand[]">
                     </td>
                     <td>
                        <label for="qty">Quantity</label>
                        <input type="text" required="required" class="small" 
  id="qty"  name="qty[]" onblur="<?php echo $_SERVER['PHP_SELF'];?>">
                     </td>
                     <td>
                        <label for="prate">Purchase Rate</label>
                        <input type="text" required="required" class="small" 
 id="prate" name="prate[]">
                     </td>
                     <td>
                        <label for="tax">Tax</label>
                        <select id="tax" name="tax" required="required">
                            <option value="0">0</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                        </select>
                     </td>
                     <td>
                        <label for="srate">Selling Price</label>
                        <input type="text"  class="small"  name="srate[]">
                     </td>
                     <td>
                        <label for="amt">Total Purchase Amount</label>
                        <input type="text" required="required" class="small" 
  id="amt" name="amt[]">
                     </td>
                        </p>
                </tr>
                </tbody>
            </table>
            <script>

     document.getElementById("tax").onblur = function(){
    var tin1 = parseFloat(document.getElementById("qty").value) * 
   parseFloat(document.getElementById("prate").value)
  var tin = parseFloat(document.getElementById("tax").value) / 100
   document.getElementById("amt").value = tin  +  tin1
   }
    </script>
            <div class="clear"></div>
        </fieldset>
      <input class="submit" name="add" type="submit" value="Confirm &raquo;" 
  />

        <div class="clear"></div>
    <div id="terms">
      <h5>Terms</h5>
      <textarea disabled>Designed by Kshathriya Technologix.</textarea>
    </div>

  </div>
  </form>
 </body>

</html>

身体{
背景图片:url(“rice.png”);
}

您不应该对多个元素使用相同的
id
。元素
id
必须是唯一的。请使用
。如果您仍然需要
id
,请提供一个唯一的名称

同样对于
选择
使用
onchange
事件,而不是
onblur
。在下面的代码中,我使用了
onchange
事件

因为您使用的是jQuery,所以我用jQuery更新了代码

$('#dataTable').on('change', 'select.tax', function(){

    var parentElem = $(this).closest("tr");
    var tin = parseFloat(parentElem.find(".qty").val()) * 
parseFloat(parentElem.find(".prate").val());

    parentElem.find(".amt").val(tin * parseFloat($(this).val()));
});
演示:

函数addRow(tableID)
{
var table=document.getElementById(tableID);
var rowCount=table.rows.length;
如果(行计数<20){
var row=table.insertRow(rowCount);
var colCount=table.rows[0].cells.length;
对于(var i=0;i工作示例:

函数addRow(tableID)
{
var table=document.getElementById(tableID);
var rowCount=table.rows.length;
如果(行计数<20){
var row=table.insertRow(rowCount);
var colCount=table.rows[0].cells.length;

对于(var i=0;iI在你的代码中看不到任何
表单标记
在HTML中会有多个
标记?你每次都需要不同的id。元素id的值必须是唯一的!我需要我添加的所有表单的结果你添加了固定表单。但是我使用js添加其他表单。我不需要弹出窗口中的amt。你能看到我的结果吗代码片段?哦,好的……我已经用jQuery更新了我的答案。
select
事件在添加其他表单时会被触发。它不是弹出窗口,而是一个
警报,如果您不想,可以将其注释掉。您使用的是非常旧的jQuery 1.3.2版本……我的代码将在jQuery版本>1.7中工作
$('#dataTable').on('change', 'select.tax', function(){

    var parentElem = $(this).closest("tr");
    var tin = parseFloat(parentElem.find(".qty").val()) * 
parseFloat(parentElem.find(".prate").val());

    parentElem.find(".amt").val(tin * parseFloat($(this).val()));
});