【发布时间】:2014-10-03 09:46:23
【问题描述】:
我已经实现了一个 jquery modal popup
Jquery 代码:-
<script type="text/javascript">
$(function(){
$('#<%=a2.ClientID %>').click(function(){
$('#modelPopup').dialog({
title: "Add New Server",
width:650,
height:450,
modal:true,
buttons:{
Close:function(){
$(this).dialog('close');
}
}
});
});
})
</script>
HTML:-
<asp:Button ID="btnAddNewServic" Text="Add Service" runat="server"
CssClass="btnSmall_bg_green" Height="26px" Width="98px" OnClick="btnAddNewServic_Click" />
代码隐藏:-
protected void btnAddNewServic_Click(object sender, EventArgs e)
{
int rowCount = 0;
rowCount = Convert.ToInt32(Session["clicks"]);
rowCount++;
Session["clicks"] = rowCount;
for (int i = 0; i < rowCount; i++)
{
TextBox txtServerU = new TextBox();
Label lblU = new Label();
txtServerU.ID = "txtServerU" + i.ToString();
lblU.ID = "lblU" + i.ToString();
lblU.Text = "Service" + (i + 1).ToString() + ":";
panelnewserver.Controls.Add(lblU);
panelnewserver.Controls.Add(txtServerU);
}
}
我无法找到此代码的问题。谁能帮我触发这个按钮点击事件。提前致谢。
更新:-
JQuery 代码:-
$(function(){
$('#<%=a2.ClientID %>').click(function(){
var $dialog= $('#modelPopup').dialog({
autoopen:false,
title: "Add New Server",
width:650,
height:450,
modal:true,
buttons:{
Close:function(){
$(this).dialog('close');
}
}
});
$dialog.parent().appendTo($("form:first"));
return false;
});
})
</script>
现在按钮单击事件被触发,但在完成我的过程后,模式弹出窗口将自动关闭。谁能帮我解决这个问题。
【问题讨论】:
-
首先我建议更改 $(function() {});成为 $(document().ready(function()});
-
你在 FireBug 中检查过,点击事件真的触发了吗?
-
@andrey.shedko $(function(){}) 非常好用,只是放置 $(document).ready(function() 的更短方式
-
它并不总是完美无缺,因为这可能与页面生命周期有关。
-
@andrey.shedko 你错了。如果您不相信我,请阅读 jQuery api.jquery.com/ready
标签: javascript c# jquery asp.net