calulate function in javascript for dynamically added field

前端 未结 2 2077
情话喂你
情话喂你 2020-12-22 11:40

I want to calculate subtotal and total for my form

i tried some javascripts but dident worked for me

some of them were only for static table since i am addi

2条回答
  •  悲&欢浪女
    2020-12-22 12:06

    If I understood you correctly, the code you are looking for should look something like this:

    var values = document.querySelectorAll('input.amnt'),//find all inputs  
                                                    //that you need to add 
                                                    //use regular dom selector 
                                                    //like in css
        subtotal = 0;
    
    for(var i = 0, ; = values.length; i

    It'll always add all the vales in the documents, you can add or remove data, doesn't matter.

    PS please do not use

    tag - it's deprecated, you should be using css for that.

提交回复
热议问题