因此,这应该更改页面,以便当他们单击按钮时,它会显示他们在表单中选择的所有内容的总数,但它没有执行任何操作。看起来它根本没有运行脚本,我不知道发生了什么。
...more form stuff up here
<button type="button" onclick="total(this.form)">Get my Total</button>
<p id="subtotal"></p>
<input type="submit">
</form>
<script>
function total(form)
{
var SynCr= form.Synth.value;
document.getElementById("subtotal").innerHTML="You have ordered: <br>"+SynCr+" Synth");
}
</script>
最佳答案
您的问题是onclick="total(this.form)"
。当调用处理程序时,this
引用按钮,该按钮没有表单作为成员。
尝试一下:
onclick="total(document.getElementById('formId'))"
关于javascript - 按钮未运行 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21944456/