HTML表单所需的命令不起作用? [英] HTML form required command not working?

查看:98
本文介绍了HTML表单所需的命令不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我搜索了一下,发现这个命令应该是用来填写表单的。做这个简单的命令

 < input type =textname =nameid =nameplaceholder =Name required /> 

但由于某种原因,我的表单即使在指定的字段未完成时也会提交。



我甚至尝试在Dreamweaver中创建一个全新的文件,只用一个必需的输入项并提交按钮,然后在不同的浏览器中尝试它,并且它不适用于Chrome或苹果浏览器。我完全从我在这里找到的YouTube视频中完全复制,但没有运气 http://www.youtube.com / watch?v = M73FroYgkt0



这是我的网站,您可以查看代码。表单位于底部。



http://www.YourFlyersDelivered

解决方案

您的表单的问题不是您的html,而是您的javascript。



在config.js的第33行中,您有以下行:

  jQuery('form .form-b​​utton-submit')。click(function(e){e.preventDefault(); jQuery(this).closest('form')。submit();}); 

这一行阻止了您的提交按钮的默认操作,绕过了input元素的必需属性,并提交表格。如果你删除了这一行,我相信它会起作用。举例:



你当前的表单提交方法: http://jsfiddle.net/Daedalus/2FY9g/ < - 不起作用

如果不阻止默认操作: http://jsfiddle.net/Daedalus/2FY9g/1/ < - 作品


I'm trying to get my form to require certain fields be filled out before the form can be submitted.

I searched and found that the command is supposed to be this simple command

<input type="text" name="name" id="name" placeholder="Name" required />

But for some reason on my form it submits it even when specified fields are not completed.

I even tried creating a brand new file in Dreamweaver with a new form with just a required input item and submit button and tried it in different browsers and it didn't work in Chrome or Safari. I copied it exactly from a YouTube video I found here with no luck http://www.youtube.com/watch?v=M73FroYgkt0

Here is my site so you can examine the code. The form is at the bottom.

http://www.YourFlyersDelivered.com

解决方案

The problem with your form isn't your html, it is your javascript.

On line 33 of config.js, you have the following line:

jQuery('form .form-button-submit').click(function(e) { e.preventDefault(); jQuery(this).closest('form').submit(); });

This line is preventing the default action of your submit button, bypassing the required attribute on your input element, and submitting the form. If you remove this line, I'm sure it will work.. Examples:

Your current method of form submission: http://jsfiddle.net/Daedalus/2FY9g/ <- does not work

Without the default action prevented: http://jsfiddle.net/Daedalus/2FY9g/1/ <- works

这篇关于HTML表单所需的命令不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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