Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.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乘法_Javascript_Jquery_Html - Fatal编程技术网

添加行时的Javascript乘法

添加行时的Javascript乘法,javascript,jquery,html,Javascript,Jquery,Html,我的代码有一个问题,当我添加javascript乘法时没有运行,但在第一行就可以了。我认为问题id必须是唯一的,并且我更改为名称,但仍然不起作用 你可以试试下面的mycode function multiplyBy(){ num1=document.getElementById(“input1”).value; num2=document.getElementById(“input2”).value; document.getElementById(“输出”).value=num1*num2;

我的代码有一个问题,当我添加javascript乘法时没有运行,但在第一行就可以了。我认为问题id必须是唯一的,并且我更改为名称,但仍然不起作用

你可以试试下面的mycode

function multiplyBy(){
num1=document.getElementById(“input1”).value;
num2=document.getElementById(“input2”).value;
document.getElementById(“输出”).value=num1*num2;
}
$(文档).ready(函数(){
$(“#addCF”)。单击(函数(){
$(“#customFields”).append('1');
});
$(“#customFields”)。在('click','.remCF',function()上{
$(this.parent().parent().remove();
});
});

#
纳马巴朗
哈尔加
数量
小计
1.

Baris Baru(F7)
整个文档中
id
属性的值必须是唯一的。每次进行计算时,您都在添加另一个id为
输出的元素。DOM不知道你指的是哪一个

我认为问题id必须是唯一的,我将更改为名称

是的,就是这样,
id
在同一文档中应该是唯一的,相反,您不需要
id
,在这里最好使用公共类:

<tr>
    <td>
      <input class="form-control" name="kode_barang[]" placeholder="Ketik Kode / Nama Barang" type="text">
    </td>
    <td>
      <input class="form-control calculation" name="harga_satuan[]" value="" type="text">
    </td>
    <td>
      <input class="form-control calculation" name="jumlah_beli[]" type="text">
    </td>
    <td>
      <input class="form-control output" name="sub_total[]" id="" type="text">
    </td>
    <td>
      <button class="remCF"><i class="fa fa-times" style="color:red;"></i></button>
    </td>
</tr>

#
纳马巴朗
哈尔加
数量
小计
1.

Baris Baru(F7)
您多次使用同一个id,它在jquery/javascript中给出了错误的行为。我在每个文本框中添加了一些类,并用on
keyup
jquery函数替换了
multiplyby
函数

在你的页面上试试这个,看看它能提供你想要的输出

$(document).on('keyup','input',function()){
var num1=$(this).parents('tr:first').find('input:first').val();
var num2=$(this).parents('tr:first').find('.input:last').val();
$(this).parents('tr:first').find('sub-total').val(num1*num2);
});
$(文档).ready(函数(){
$(“#addCF”)。单击(函数(){
$(“#customFields”).append('1');
});
$(“#customFields”)。在('click','.remCF',function()上{
$(this.parent().parent().remove();
});
});

#
纳马巴朗
哈尔加
数量
小计
1.
巴里斯巴鲁(F7)
井<代码>onkeyup=“calc()”
?那是什么意思?删除它,因为没有
calc
功能。