我正在使用 jQuery 弹出窗口,用户可以从中保存数据。当我从本地计算机(Web 项目)运行应用程序时,会显示弹出窗口并且一切正常,但是一旦我尝试在服务器端执行相同的功能,它就不会在表单上显示弹出窗口。
我正在使用以下 jscript:
<script src="Scripts/jquery-1.7.1.min.js"></script>
<script src="Scripts/jquery-ui-1.8.17.custom.min.js"></script>
我显示模式弹出窗口的脚本如下:
<script type="text/javascript">
function showdialogServiceType() {
$(function () {
$("#dialogServiceType").dialog("open");
});
return false;
}
$(function () {
$("#dialogServiceType").dialog("destroy");
var dlgServiceType = $("#dialogServiceType").dialog({
title: "Service Type",
autoOpen: false,
modal: true,
resizable: true,
width: 'auto',
buttons: {
Cancel: function () {
$(this).dialog("close");
}
}
});
dlgServiceType.parent().appendTo(jQuery("form:first"));
});
</script>
为了显示上述查询,我在 GridView 中使用图像按钮。我按如下方式调用此弹出窗口:
protected void SelectVehicleReg_Click(object sender, EventArgs e)
{
ImageButton lb = sender as ImageButton;
GridViewRow row = (GridViewRow)lb.NamingContainer;
txtRowID.Text = row.Cells[0].Text;
txtVehicleReg.Text = row.Cells[1].Text;
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "popServiceType", "showdialogServiceType();", true);
}
我也尝试过使用 jquery 构建一个简单的消息框,但这不起作用(尽管它适用于服务器端的其他项目)。弹出窗口只是不想在发布后在此 Web 项目中工作。
我的测试消息对话框:
$(function () {
$("#dialog").dialog("destroy");
$("#dialog").dialog({
title: "Message",
autoOpen: false,
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
}
}
});
});
function showMessage() {
$(function () {
$("#dialog").dialog("open");
});
return false;
}
<div id="dialog" style="display: none">
<asp:Label ID="lbljQMessage" runat="server" Text=""></asp:Label>
</div>
protected void Button1_Click(object sender, EventArgs e)
{
lbljQMessage.Text = "Test";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "popUpMessage", "showMessage();", true);
}
我是不是做错了什么?
最佳答案
您确定您正确引用了 jquery 吗?我的意思是服务器将具有与本地计算机不同的路径。在浏览器中使用内置调试器 (F12) 查看 js 文件是否正确包含(如果是,它们将显示为链接,您可以打开它)。您也可以检查脚本是否在同一调试器中执行。如果您使用 Chrome,请转到“源”选项卡并选择您的站点。您可以在脚本中放置断点。然后你会看到脚本是否被执行或者可能有一些错误。
关于javascript - 弹出窗口在服务器端不起作用,但在本地起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23380778/