我正在制作一个基本的美元转换器,用于 html/javascript 练习。 但是,当我选择欧元选项时,它的作用与比索选项相同。
<html>
<head>
<title>Currency Converter</title>
<style>
</style>
</head>
<body>
<input id="amount"> </input>
<p>usd Contverted to</p>
<p class="output"> </p>
<select id="select"> <option value="1">Peso's</option> <option value="2">Euro's</option> </select>
<p id="answer"> is </p>
<input type="submit" value="Submit" onclick="run()">
<script>
function run() {
var Amount = document.getElementById("amount").value;
if (select = 1) {
document.getElementById("answer").innerHTML = "=-=-= " + Amount * 16.39 + " =-=-=";
} else if (select = 2) {
document.getElementById("answer").innerHTML = "=-=-= " + Amount * 0.9 + " =-=-=";
} else {
}
</script>
</body>
</html>
最佳答案
你不是在比较选择,你是在设置它。
if (select == 1) {
document.getElementById("answer").innerHTML = ...
} else if (select == 2) {
- = -> 设置一个值
- == -> 比较
关于javascript - html输入框出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32004755/