1

我通过 AJAX 将一些元素拉到我的页面上。这些元素是这样出现的:

<div id="offerWrapper7" class="offerWrapper">
    <div class="resultsSummaryBox bevelBox" style="">
        <div class="imgBox">
            <div class="titleBox">Title Title<br>
                    <span class="infoButton" id="info592">i</span>
            <div class="resultsBoxFullText" id="info592">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
            </div>
        </div>
    </div>
</div>

我需要绑定一个点击事件,.infoButton然后打开一个 jQuery UI 对话,内容为.resultsBoxFullText.

我已经设法使用 live() 实现了这一点(如下所示)。

$(".infoButton").live('click', function(){
    $( "#info594" ).dialog({
        height:400,
        width:600,
        show: 'fade',
        hide: 'fade'
    });
});

随着直播被贬值,有人可以告诉我如何使用 on() 来做到这一点。我认为这就像用 on 替换 live 一样简单,但似乎情况并非如此。

4

1 回答 1

5
$("an-element-already-on-the-page").on('click', '.infoButton', function(){

之前的选择器.on必须已经在页面上,并且目标元素 ( .infoButton) 必须在其中。所以你可以使用文档或正文。

于 2012-06-27T23:40:00.610 回答