简体   繁体   English

绑定到.load()div中的控制事件

[英]Bind to event of control within .load() div

I have a jQuery UI dialog whose content is populated using .load(), and then displayed. 我有一个jQuery UI对话框,其内容使用.load()填充,然后显示。 What I need to do is somehow bind to a button within the loaded HTML to close that dialog. 我需要做的是以某种方式绑定到加载的HTML中的按钮以关闭该对话框。

Code: 码:

<div id="popup">
    <div id="popupContent"></div>
</div>

<script>
    $("#popupContent").load('some_URL_within_site_that_has_a_button', function () {
        $("#popup").dialog("open");
    });
</script>

I've tried a few different things, w/o success: 我尝试过几个不同的事情,但没有成功:

$("#popupContent").find(".CloseButton").on("click", function () {
    alert("this worked");
});
$(".CloseButton").on("click", function () {
    alert("this worked");
});

Any ideas on how to bind to the dynamically loaded control events? 关于如何绑定到动态加载的控件事件的任何想法?

You are close: 你很近:

$("#popup")
    .dialog("open")
    .on("click", ".CloseButton", function() { ... });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM