Converting string to number in javascript/jQuery

后端 未结 9 1876
攒了一身酷
攒了一身酷 2021-01-31 13:08

Been trying to convert the following to number:

9条回答
  •  后悔当初
    2021-01-31 14:07

    You should just use "+" before $(this). That's going to convert the string to number, so:

    var votevalue = +$(this).data('votevalue');
    

    Oh and I recommend to use closest() method just in case :)

    var votevalue = +$(this).closest('.btn-group').data('votevalue');
    

提交回复
热议问题