简体   繁体   English

提交按钮不起作用

[英]Submit button doesn't work

I have a form with <input type="submit" .我有一个带有<input type="submit"的表单。 In chrome submit doesn't do anything.在 chrome 中,提交不执行任何操作。 On a .network" in tab in developer tools I see nothing. No errors in developer tools either. Meanwhile, if I do save a page and open a saved page, then after I press submit button, I see something appears in .network" tab.在开发人员工具选项卡中的 .network" 上,我什么也看不到。开发人员工具中也没有错误。同时,如果我保存页面并打开保存的页面,然后在我按下提交按钮后,我看到一些东西出现在 .network"标签。 This happens in chrome and firefox. This works as expected in IE.这发生在 chrome 和 firefox 中。这在 IE 中按预期工作。

Does anybody have a hindsight, what should I look at?有没有人有后见之明,我应该看什么?

EDIT: I don't need a direct answer, I only need to know, where should I look at.编辑:我不需要直接回答,我只需要知道,我应该看哪里。 If someone posts a direction and that'll help me to solve my problem, I'll accept it as a correct answer.如果有人发布了一个方向并且可以帮助我解决我的问题,我会接受它作为正确答案。

EDIT2: Structure of a page looks like this: EDIT2:页面结构如下所示:

html
    head
    body
        div
        div
            form
            form
            form
            form
            form
                input
                input
                table
                table
                    tbody
                        tr..td..input type=submit

EDIT3: We found the actual problem, it was that in a page was a link, containing href="#" and after clicking on that link submit stopped to work, because # was added to the end of URL and because action of the form was empty so it picked up URI from current URI, which contained # at the, so instead of submitting, browser did jump on a current page. EDIT3:我们发现了实际的问题,它是在一个页面中有一个链接,包含href="#"并且在单击该链接后提交停止工作,因为#被添加到 URL 的末尾并且因为表单的action是空的,所以它从当前 URI 中获取 URI,其中包含# ,因此浏览器没有提交,而是跳转到了当前页面。

If you are not using any javascript/jquery for form validation, then a simple layout for your form would look like this.如果您没有使用任何 javascript/jquery 进行表单验证,那么您的表单的简单布局将如下所示。

within the body of your html document:在您的 html 文档正文中:

<form action="formHandler.php" name="yourForm" id="theForm" method="post">    
    <input type="text" name="fname" id="fname" />    
    <input type="submit" value="submit"/>
</form>

You need to ensure you have the submit button within the form tags, and an appropriate action assigned.您需要确保在表单标签中有提交按钮,并分配了适当的操作。 Such as sending to a php file.比如发送到一个php文件。

For a more direct answer, provide the code you are working with.要获得更直接的答案,请提供您正在使用的代码。

You may find the following of use: http://www.w3.org/TR/html401/interact/forms.html您可能会发现以下用法: http : //www.w3.org/TR/html401/interact/forms.html

Are you using HTML5?你在使用 HTML5 吗? If so, check whether you have any <input type="hidden"> in your form with the property required .如果是这样,请检查您的表单中是否有任何具有required属性的<input type="hidden"> Remove that required property.删除required属性。 Internet Explorer won't take this property, so it works but Chrome will. Internet Explorer 不会接受这个属性,所以它可以工作,但 Chrome 会。

I faced this problem today, and the issue was I was preventing event default action in document onclick:我今天遇到了这个问题,问题是我阻止了文档 onclick 中的事件默认操作:

document.onclick = function(e) {
    e.preventDefault();
}

Document onclick usually is used for event delegation but it's wrong to prevent default for every event, you must do it only for required elements:文档 onclick 通常用于事件委托,但阻止每个事件的默认值是错误的,您必须仅对必需元素执行此操作:

document.onclick = function(e) {
    if (e.target instanceof HTMLAnchorElement) e.preventDefault();
}

Check if you are using any sort of jquery/javascript validation on the page and try disabling it and see what happens.检查您是否在页面上使用任何类型的 jquery/javascript 验证并尝试禁用它,看看会发生什么。 You can use your browser's developer tools to see if any javascript file with validate or validation is being loaded.您可以使用浏览器的开发人员工具查看是否正在加载任何带有验证或验证的 javascript 文件。 You can also look for hidden form elements (ie. style set to display:none; or something like that) and make sure there isn't a hidden validation error on those that's not being rendered.您还可以查找隐藏的表单元素(即样式设置为 display:none; 或类似的东西)并确保未呈现的那些元素没有隐藏的验证错误。

Hello from the future.来自未来的你好。

For clarity, I just wanted to add (as this was pretty high up in google) - we can now use为了清楚起见,我只想添加(因为这在谷歌中非常高) - 我们现在可以使用

<button type="submit">Upload Stuff</button>

And to reset a form并重置表格

<button type="reset" value="Reset">Reset</button>

Check out button types查看按钮类型

We can also attach buttons to submit forms like this :我们还可以将按钮提交表单就像这样

<button type="submit" form="myform" value="Submit">Submit</button>

I ran into this on a friend's HTML code and in his case, he was missing quotes.我在朋友的 HTML 代码上遇到了这个问题,在他的情况下,他缺少引号。

For example:例如:

<form action="formHandler.php" name="yourForm" id="theForm" method="post">    
<input type="text" name="fname" id="fname" style="width:90;font-size:10>     
<input type="submit" value="submit"/>
</form>

In this example, a missing quote on the input text fname will simply render the submit button un-usable and the form will not submit.在此示例中,输入文本 fname 上缺少引号只会使提交按钮无法使用,并且表单将不会提交。

Of course, this is a bad example because I should be using CSS in the first place ;) but anyways, check all your single and double quotes to see that they are closing properly.当然,这是一个不好的例子,因为我应该首先使用 CSS ;) 但无论如何,请检查所有单引号和双引号以查看它们是否正确关闭。

Also, if you have any tags like center, move them out of the form.此外,如果您有任何标签,如中心,请将它们移出表单。

<form action="formHandler.php" name="yourForm" id="theForm" method="post">  
<center> <-- bad

As strange it may seems, it can have an impact.看起来很奇怪,但它会产生影响。

You can't have a form element as a child (directly or indirectly) of another form element.您不能将form元素作为另一个form元素的子元素(直接或间接)。

If the following does not return null then you need to remove the excess form elements:如果以下不返回null则您需要删除多余的form元素:

document.querySelectorAll('form form');//Must return null to be valid.

check your form is outside the table检查你的表格在桌子外面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM