Sum of two input value by jquery

前端 未结 7 2169
滥情空心
滥情空心 2020-12-06 04:30

I have code :

function compute() {
    if ($(\'input[name=type]:checked\').val() != undefined) {
        var a = $(\'input[name=service_price]\').val();
             


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 05:06

    Cast them to a Number

    $('#total_price').val(Number(a)+Number(b));
    

    But before you do that

    if (!isNaN($('input[name=service_price]').val()) {...
    

提交回复
热议问题