English 中文(简体)
用 j子支付多种形式之一
原标题:Sending one of multiple forms with jQuery

我做的是:

$.each(data2, function(key2, val2) {
    $( #posts ).append( <div class="send_comment" align="right"> );
    $( #posts ).append( <input type="hidden" class="com_post_id" value=" +i+ "><br /> );
    $( #posts ).append( Author: <input type="text" class="com_author"><br /> );
    $( #posts ).append( Img: <input type="text" class="com_img"><br /> );
    $( #posts ).append( Text: <input type="text" class="com_text"><br /> );
    $( #posts ).append( <button class="new_comment">Send</button> );
    $( #posts ).append( </div> );
});

我怎么能用<代码>美元>寄出? 有了<代码>(这一条),我可以找到被点击的元件,但随后又能找到?

最佳回答

由于其是动态注入元素,因此,应当使用<代码>j对功能进行约束。 Query on

  $(function(){
      $(".send_comment").on("click",".new_comment",function(e){
         e.preventDefault();
         var item=$(this);
         var postId=item.parent().find(".com_post_id");   
         var author=item.parent().find(".com_author");  
         var msg=item.parent().find(".com_text");  

         $.post("yourPage.php", { id : postId, author:author ,msg:msg },function(result){
             //do whatever with result
              alert(result);
         });

      });
    });

http://api.jquery.com/on/

j Query on将就当前和未来的内容开展工作。

问题回答

<代码>数据=(原文)。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签