简体   繁体   English

为什么我不能提交表格?

[英]Why can't I submit my form?

I have a modal popup, that I want to hide when the 'shade' is clicked, but not when the contents are clicked. 我有一个模态弹出窗口,我想在单击“阴影”时隐藏,但不是在单击内容时隐藏。 For this purpose I have: 为此,我有:

$('#shade').click(function(){
  $('#shade').fadeOut();
}).children().click(function(e){
  return false;
});

The problem is I have a form inside that I want to submit, and this code prevents the form from submitting, so I have: 问题是我有一个我要提交的表单,这段代码阻止表单提交,所以我有:

$('#shade-form-submit').click(function(){
  document.getElementById('shade-form').submit();
});

However this results in the following error in the console: 但是,这会导致控制台中出现以下错误:

[13:07:21.145] TypeError: document.getElementById(...).submit is not a function @ ...

What's going on? 这是怎么回事? For reference, my <form> tag: 作为参考,我的<form>标签:

<form action='.' method='post' id='shade-form'> 
  <div>
    <input type='text' />
  </div>
  <div>
     <div>
       <input type='submit' />
     </div>
  </div>
</form>

You need to exclude form inputs from the click handler you have on children() : 您需要从children()上的单击处理程序中排除表单输入:

$('#shade')
    .click(function(){
        $('#shade').fadeOut();
    })
    .children().not(':input').click(function(e){
        return false;
    });

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

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