0

这只是应用于我获取文本的文本区域的触发器和 a.comment 触发器之间的冲突

// 先读上面

为什么在页面加载时第一次单击时此 ON 方法不起作用?. 只是因为我点击了页面的任何部分,在第二次点击时,点击事件才起作用。有任何想法吗?顺便说一句,我正在将 firefox 与 firebug 一起使用,如果您知道一种方法可以在 firebug 面板中获取有关此奇怪行为的更好信息的方法。我会感谢你的任何帮助。我正在使用 jquery-1.7.2.min 。

$(document).ready(function(){

    $('a.comment').on("click", function(event){
   event.preventDefault();
       var comment_text = $("#comment").val();
   if(comment_text !="Escriba aqui su comentario")
       {
      $.post("../load.php?comment_text="+comment_text, function(response){
        //on response
      })
       }
    });

});

这是html部分:

<textarea id="comment"></textarea> /*only one on the page*/
<a id="c_id-XXX" class="comment"> Comment</a>  /* XXX = diferent num*/
4

1 回答 1

1

看看这里

我已经编辑了你的工作,现在很好:

$(document).ready(function(){

    $('a.comment').on("click", function(event){
   event.preventDefault();
      alert('in'); //testing if we are in
       var comment_text = $("#comment").val();
   if(comment_text !="Escriba aqui su comentario")
       {
//no need for extra brackets here as long as you are not passing args.
      $.post("../load.php?comment_text="+comment_text,  
 function(response){
        //on response
      }); // no use for settimeout()
       }
      alert('out'); // checking that we have done it :)
    });     

});

希望我有所帮助

于 2013-01-08T19:04:00.687 回答