How to force JS to do math instead of putting two strings together
问题 I need javascript to add 5 to an integer variable, but instead it treats the variable as a string, so it write out the variable, then add 5 onto the end of the \"string\". How can I force it to do math instead? var dots = document.getElementById(\"txt\").value; // 5 function increase(){ dots = dots + 5; } Output: 55 How can I force it to output 10 ? 回答1: You have the line dots = document.getElementById("txt").value; in your file, this will set dots to be a string because the contents of txt