Jquery 如何使提交按钮在文本区域上保持可见和可执行

Jquery 如何使提交按钮在文本区域上保持可见和可执行,jquery,blur,Jquery,Blur,我有一个标签,它包含一个包含两个元素的表单:一个textarea框和一个submit按钮 $('textarea').blur(function() { $('#comment_posting_holder').hide(); }); 我想让div标签(包含textarea和submit按钮)在我单击submit按钮之外的其他位置时消失。下面的代码我有一个开始。因此,在离开文本区域的焦点时,我可以使div标记消失 问题是,如果div消失,提交按钮也会消失,这意味着我无法提交表单!我怎

我有一个
标签,它包含一个包含两个元素的表单:一个textarea框和一个submit按钮

$('textarea').blur(function() {
     $('#comment_posting_holder').hide();
});
我想让div标签(包含textarea和submit按钮)在我单击submit按钮之外的其他位置时消失。下面的代码我有一个开始。因此,在离开文本区域的焦点时,我可以使div标记消失

问题是,如果div消失,提交按钮也会消失,这意味着我无法提交表单!我怎样才能解决这个问题

有什么建议吗?谢谢大家!

**Facebook通过其评论做到了这一点。如果单击“发表评论…”字段,文本区域将出现,然后在失去焦点时消失,而不是按“提交”按钮

$('textarea').blur(function() {
     $('#comment_posting_holder').hide();
});

由于代码中的语法错误,Was无法工作。除了缺少的单引号外,只要是在实际触发的事件中,您所拥有的看起来不错。试试这个:

$(document).ready(function(){
    $('textarea').blur(function() {
        $('#comment_posting_holder').hide();
    });
});

如果你想要像facebook这样的实现,你需要检查是否有人在文本框中写了什么

你可以看到我的答案有效

HTML

一些CSS

.comment_empty {
   color: gray;
   height: 30px;
}

.comment_filled {
   color: black;
   height: 100px;
}

我了解您想要什么:
如果用户在任何地方单击,而单击的元素不是submit按钮,则隐藏div

执行此操作的代码:

$(document).ready(function() {
  $(document).click(function(event) {
    if (event.target.id == "idOfSubmitButton") {
      //user clicked the submit button (make sure to give it an ID)
      //if you wanted to be really hardcore, you could submit the form here via AJAX
    }
    else {
      //user clicked anywhere on the page but the submit button
      //here you'd want to check and make sure someone has actually typed
      //something in the textarea, otherwise this will happen for every
      //click on a hyperlink, button, image, et cetera on the page
      $('#comment_posting_holder').hide();
    }
  });
});

好吧,我上面打错了,但不,这不是问题所在。看,问题出在这里。。。提交按钮也会消失。我不想让它消失!那时我不能提交表格。明白我的意思吗?由于div标记本身持有textarea和submit按钮,一旦textarea失去焦点,一切都会消失!我只是想让所有的东西都消失,只要我点击其他地方,这就是代码的这一部分将要做的是。但是,当我放上鼠标并点击提交按钮时,一切都消失了。
$(document).ready(function() {
  $(document).click(function(event) {
    if (event.target.id == "idOfSubmitButton") {
      //user clicked the submit button (make sure to give it an ID)
      //if you wanted to be really hardcore, you could submit the form here via AJAX
    }
    else {
      //user clicked anywhere on the page but the submit button
      //here you'd want to check and make sure someone has actually typed
      //something in the textarea, otherwise this will happen for every
      //click on a hyperlink, button, image, et cetera on the page
      $('#comment_posting_holder').hide();
    }
  });
});