I have a simple input control :
<input type="text" min="0" max="100" value="0">
then I do a sum compute:
var a=10;
console.log(a+$('input').val());
however the result is ‘100’,not ’10’?!
why ?how can I get the correct answer?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem is that
$('input').val()is a string, soais converted to a string, and the+concatenates them. Try:This will convert the value of the textbox to a number, allowing the
+to be the addition operator.