How to make an addition instead of a concatenation

后端 未结 4 1295
遥遥无期
遥遥无期 2020-12-21 00:53

I have an input button. I created for this input an attribute called \"multiplicateur\" which has the value of 1. When the button is clicked I have a .click() t

相关标签:
4条回答
  • 2020-12-21 01:31

    In order to add value with decimal point, please use parseFloat(ajaxData)

    alert(parseFloat(ajaxData) + 1);

    0 讨论(0)
  • 2020-12-21 01:40

    ajaxData is a string. Thus, you need to parse it to an integer...

     $('#envoyer').click(function() {
        const ajaxData = $(this).attr('multiplicateur');
    
        /* parse string to integer */
        alert(parseInt(ajaxData) + 1);
    
    });
    
    0 讨论(0)
  • 2020-12-21 01:40

    For substracting

    function removeFromQtt(){
                 $("qty").value = parseInt($("qty").value)-1;
     }
    

    For addition

    function add(){
                 $("qty").value = parseInt($("qty").value)+1;
     }
    
    0 讨论(0)
  • 2020-12-21 01:42

    You have to parse it first:

        parseInt(ajaxData)+1;
    
    0 讨论(0)
提交回复
热议问题