我在main中有一个加载对话框的函数:
<a href="#" class="insert" onclick="return openDialog('AddEditUser.aspx',350);">Add new</a>这是因为所有的jquery脚本都是在main的开头加载的,而且我已经定义了openDialog函数。
但在打开的页面'AddEditUser.aspx‘中,有以下代码来关闭末尾的对话框:
string script = @"jquery('#dialog').html('');jquery('#dialog').dialog('destroy');window.location.reload()";
ScriptManager.RegisterClientScriptBlock(this, typeof(UpdatePanel), "jscript", script, true);当我运行程序时,我总是在最后的JScript代码序列中得到错误"Runtime-error Microsoft : Object expected“。
我在谷歌上搜索了这个错误,结果显示这是因为jquery没有加载,但这是因为对话框打开了。此错误的原因是什么?
发布于 2011-09-02 00:24:06
openDialog是做什么的?我相信它会打开一个新窗口,并加载你传递给它的页面。您确定要打开的新页面(AddEditUser.aspx)上有jQuery吗?我发现这个问题是因为它在新页面中找不到jQuery。
此外,还应该将内联js包装在$(function(){})just to ensure that dom is ready and#dialogis available tojQuery`.中。尝尝这个
string script = @"jquery(function(){jquery('#dialog').html('');jquery('#dialog').dialog('destroy');window.location.reload();});";
ScriptManager.RegisterClientScriptBlock(this, typeof(UpdatePanel), "jscript", script, true);https://stackoverflow.com/questions/7272984
复制相似问题