我正在尝试解决我在ASP.Net应用程序中使用jQuery的对话框时遇到的问题.
我有两个对话框,页面tos_text和tos_thankyou它们当然简单的<div>操作内容显示标签.
首先,我使用Google CDN来引用jQuery:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当我尝试附加jQuery对话框方法时,浏览器声称该对象上不存在对话框方法.由于我使用ASP.Net,我在运行时有条件地在Page_PreRender事件处理程序中注入javascript :
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "RegisterThankYouDialog",
"\n<script type='text/javascript'>$(function() { $('#tos_thankyou').dialog({ autoOpen: false, modal: true, buttons: { Ok : function() { $(this).dialog('close'); } } }); });</script>\n", false);
ScriptManager.RegisterStartupScript(this, GetType(), "RegisterTOSDialog",
"\n<script type='text/javascript'>$(function() { $('#tos_text').dialog({ autoOpen: false, modal: true, }); });</script>\n", false);
if (Show || ForceShow)
{
ScriptManager.RegisterStartupScript(this, GetType(), "ShowTOSDialog",
"\n<script type='text/javascript'>$(function() { $('#tos_text').dialog('open'); });</script>\n", false);
}
if (ShowThankYou)
{
ScriptManager.RegisterStartupScript(this, GetType(), "ShowThankYou",
"\n<script type='text/javascript'>$(function() { $('#tos_thankyou').dialog('open'); });</script>\n", false);
}
}
Run Code Online (Sandbox Code Playgroud)
这是呈现的代码(来自Chrome JS控制台,包含错误):
<script type="text/javascript">
//<![CDATA[
(function() {var fn = function() {$get("ctl00_smScripts_HiddenField").value = '';Sys.Application.remove_init(fn);};Sys.Application.add_init(fn);})();//]]>
</script>
<script type='text/javascript'>new Sys.WebForms.Menu({ element: 'ctl00_NavigationMenu', disappearAfter: 500, orientation: 'horizontal', tabIndex: 0, disabled: false });</script>
<script type='text/javascript'>$(function() { $('#tos_thankyou').dialog({ autoOpen: false, modal: true, buttons: { Ok : function() { $(this).dialog('close'); } } }); });</script>
default.aspx:610Uncaught TypeError: Object [object Object] has no method 'dialog'
<script type='text/javascript'>$(function() { $('#tos_text').dialog({ autoOpen: false, modal: true, }); });</script>
<script type='text/javascript'>$(function() { $('#tos_text').dialog('open'); });</script>
<script type="text/javascript">
//<![CDATA[
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.ModalPopupBehavior, {"BackgroundCssClass":"modalBackground","CancelControlID":"ctl00_MainContent_btnPrivacyOK","PopupControlID":"ctl00_MainContent_pnlPrivacy","dynamicServicePath":"/default.aspx","id":"ctl00_MainContent_ModalPopupExtender1"}, null, null, $get("ctl00_MainContent_btnPrivacy"));
});
//]]>
</script>
Run Code Online (Sandbox Code Playgroud)
该对话框的方法是jQuery的UI脚本的一部分.将其添加到您的页面:
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
您可能还想添加相关的样式表:
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5725 次 |
| 最近记录: |