我可以使用 Jquery 提交表单,但我不明白为什么 this.form.submit()
不能使用 vanilla javascript?我正在使用 Chrome 进行测试.
解决方案
div
不是表单元素.它没有 this.form
.
你仍然可以做 document.forms.form.submit()
(.form
因为你有 name="form"
)
I was trying to test form submission using mouse clicks but the form doesn't seem to submit with vanilla javascript.
I'm using this simple markup and code:
<form name="form" id="price" action="" method="post">
<div class="category" name="price" value="50 dollars"
onClick="this.form.submit();"
>price</div>
</form>
<?php
echo $_POST['price'];
?>
I can submit the form with Jquery, but I don't understand why this.form.submit()
is not working with vanilla javascript? I'm using Chrome to test this.
解决方案
A div
is not a form element. There is no this.form
for it.
You can still do document.forms.form.submit()
(.form
since you have name="form"
)
这篇关于单击表单中的 div 元素后 this.form.submit() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!