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

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

问题描述

我试图使用鼠标单击来测试表单提交,但表单似乎没有用香草javascript提交。



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

 < form name =formid =priceaction =method =post> 
< div class =categoryname =pricevalue =50 dollars
onClick =this.form.submit();
>价格< / div>

< / form>

<?php
echo $ _POST ['price'];

?>

我可以使用Jquery提交表单,但我不明白为什么 this.form.submit()不适用于香草JavaScript?

解决方案

A 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天全站免登陆