这是简单的方法: var num = Number(str); 在此示例中,str是包含字符串的变量。您可以对其进行测试并查看其工作方式:Google chrome开发人员工具,然后转到控制台并粘贴以下代码。阅读评论以更好地了解转换是如何完成的。// Here Im creating my variable as a stringvar str = "258";// here im printing the string variable: strconsole.log ( str );// here Im using typeof , this tells me that the variable str is the type: stringconsole.log ("The variable str is type: " + typeof str);// here is where the conversion happens// Number will take the string in the parentesis and transform it to a variable num as type: numbervar num = Number(str);console.log ("The variable num is type: " + typeof num);