单击表单中的 div 元素后 this.form.submit() 不起作用 [英] this.form.submit() not working after clicking div element in form

查看:23
本文介绍了单击表单中的 div 元素后 this.form.submit() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用鼠标点击测试表单提交,但表单似乎没有使用 vanilla javascript 提交.

我正在使用这个简单的标记和代码:

我可以使用 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() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆