English 中文(简体)
页: 1 当添加新的四分之二时,彩礼会失败。
原标题:jQuery event fails when a new div is added

右铭是我的 j:

$().ready(function (){
$(".contact").hover(function (){
    ...
});
$(".contact").not( .contact[id=" +activeId+ "] ).click(function (){
    ...
});
$(".contact_chooser_contact").click(function (){
    ...
    $( .contacts ).append( <div class="contact" id=" +id+ " title=" +phone+ ">
                                <div class="contact_img"><img src="src/default_face.png" width="64"/></div>
                                <div class="contact_info" id=" +name+ "> +name+  <span class="sms_number">0</span></div>
                                <div class="contact_last_sms">
                                
                                <!-- span class="last_sms_time"> echo $message[sizeof($message)-1]->time; </ -->
                                </div>
                            </div> );           
    ...
});
});

通知,在“联系——接触”中,我是如何点击手的,在“接触”中,我对另一个“联系”作了解释,但现在,当我把这个新“......联系”推向后,我会做任何事情。 我如何解决这个问题,我理解,由于我打算在我加入新的“联系”之后重新启动(“联系”)美元,但这样做是比较容易的?

最佳回答

http://api.jquery.com/on/“rel=“nofollow”>on(),利用这一手段,将人力部增加的任何内容与各自的甄选者联系起来。 <on(> over live(>>>,其优点是,你可以将背景缩小到一个光谱集装箱,而不是整个。 例如,我只将<代码>文件作为背景。

j Query 1.7 use on()。

$(document).on( mouseover ,  .contact , function(){
  ...
}); 

Less than 1.7, use delegate()

$(document).delegate( .contact ,  mouseover , function(){
   ...
}); 

小于1.4.2,使用

$( .contact ).live( mouseover , function(){
   ...
}); 
问题回答

“内容”在文件上加载时。 之后,从“接触”活动中添加的四点实际上没有发生。 由于点击事件没有再次发生。

你可以这样做:

function addDiv(div) {
    div.hover(function() {
        ...
    });
}

$(function() {

    addDiv($(".contact"));

    $(".contact_chooser_contact").click(function (){
        addDiv($( <div/> ).addClass( .contact ).attr({id:ID, title: TITLE}).append(...));
    });
});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签