除此之外,我在我的内容页面中有这个html内容:
<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
$("[ID$=panelDetail]").dialog({
autoOpen: false
, resizable: false
, height: 'auto'
, width: 'auto'
, modal: true
, overlay: { opacity: 0.8, background: "black" }
});
function loadDialog(action) {
$("[ID$=panelDetail]").dialog('open');
$.ajax({
type: "POST",
dataType: "HTML",
url: action,
data: {},
success: function(response) {
$("#panelDetail").html('');
$("#panelDetail").html(response);
}
});
}
$("[ID$=btnAdd]").click(function() {
alert("click on add");
loadDialog("/Foro/Create", "");
});
</script>
</asp:Content>
然后我将这个HTML片段分成两个分开的部分
<asp:Content ID="Content1" ContentPlaceHolderID="BodyContent" runat="server">
<div id="panelDetail" style="display:none" title="Panel Title"></div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="RightPanel" runat="server">
<a href="#" id="btnAdd">Add new</a>
<a href="#" id="btnEdit">Edit</a>
</asp:Content>
为什么标签内的警报永远不会被调用???
感谢您的帮助!
答案 0 :(得分:2)
您需要在document.ready
电话中打包,例如:
$(function() {
$("a[ID$=btnAdd]").click(function() {
alert("click on add");
loadDialog("/Foro/Create", "");
});
});
否则元素还没有被找到:) document.ready
处理程序在DOm完全加载时触发,例如你的链接就在那里。
如果是UpatePanels,请切换到.live()
,如下所示:
$(function() {
$("a[ID$=btnAdd]").live('click', function() {
alert("click on add");
loadDialog("/Foro/Create", "");
});
});