遵循代码而不是返回添加结果,将变量值附加到数字中。 PL。救命。提前谢谢。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="number" id="wd" value=1000>
<br>
Enter Height of chart
<input type="number" id="ht" value=1000>
<br>
<body>
<script type="text/javascript">
var retWidth = document.getElementById('wd').value;
var retHeight = document.getElementById('ht').value;
wd1 = retWidth + 5; // hoping to get result 1005
ht1 = retHeight + 5;
console.log("wd1 = "+wd1)
console.log("ht1 = "+ht1)
</script>
</body>
</html>
console log:
wd1 = 10005
ht1 = 10005
答案 0 :(得分:1)
使用parseInt()方法将字符串转换回数字。现在它们是字符串,所以添加两个字符串连接它们,这就是为什么你得到10005。 使用parseInt(width)+5