MVC jqueryUI 模式对话框

发布于 2025-01-08 12:23:56 字数 1328 浏览 0 评论 0原文

因此,在我尝试让 jQueryUI 正常工作的所有失败尝试中,我在下载后在 此处 尝试过这个示例来自 jQueryUI 站点的主题。

这是我的代码,在我的 asp.net mvc 页面的上面的链接中查看该示例。

<link type="text/css" href="<%= Url.Content("~/Scripts/jquery-ui/css/smoothness/jquery-ui-1.8.17.custom.css")%>" rel="stylesheet" />    
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-ui/js/jquery-1.7.1.min.js")%>"></script>
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-ui/js/jquery-ui-1.8.17.custom.min.js")%>"></script>



<script>

$('#dialog_link').click(function(){
    $('#Dialog').dialog('open');  
    return false;
});


</script>

<p id="dialog_link">Open Dialog</p> 


<div id="Dialog" title="Dialog title!">
This content shown within dialog...

</div>

按 F5 后,我希望看到一个可单击的文本,单击该文本时会弹出一个带有 [x] 按钮的模式对话框,用于关闭它并返回主窗口。但是我在页面加载时看到的是

screenshot of mvc application

其中文本“打开对话框”没有响应单击事件,并且假设的“模式对话框”已经以纯字符串的形式可见,并且没有任何格式。那么 jQueryUI 的所有魔力都到哪里去了呢?我链接正确的脚本有问题吗? 彻底迷失了。请帮忙..

编辑 这段完全相同的代码在不同的文件中以纯 html 模式运行。当我将此代码复制到我的 asp.net mvc 页面的内容标记中时,我在非描述性行处收到 javascript 错误!

So in all my failed attempts to get jQueryUI working, I have tried this example here after downloading a theme from the jQueryUI site.

and here is my code looking at that example in the link above in my asp.net mvc page.

<link type="text/css" href="<%= Url.Content("~/Scripts/jquery-ui/css/smoothness/jquery-ui-1.8.17.custom.css")%>" rel="stylesheet" />    
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-ui/js/jquery-1.7.1.min.js")%>"></script>
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-ui/js/jquery-ui-1.8.17.custom.min.js")%>"></script>



<script>

$('#dialog_link').click(function(){
    $('#Dialog').dialog('open');  
    return false;
});


</script>

<p id="dialog_link">Open Dialog</p> 


<div id="Dialog" title="Dialog title!">
This content shown within dialog...

</div>

After hitting F5 I would have expected to see a clickable text which when clicked would bring up a modal dialog with a [x] button to close it and get back to the main window. However what I get to see is this on page load,

screenshot of mvc application

where the text 'open dialog' does not respond to click events and the supposed "modal dialog" is already visible in the form of a plain string and without any formatting. So where did all the magic of jQueryUI go? Something wrong in my linking correct scripts?
Totally lost. Please help..

Edit
This exact same code works in pure html mode in a different file. when I copy this code into my asp.net mvc page within the content tags I get a javascript error at a non-descript line!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

汐鸠 2025-01-15 12:23:56

只需从 $('#Dialog').dialog('open'); 中取出“open”即可现在就可以走了。

编辑:将此 jsFiddle 添加到您的代码中作为示例:

http://jsfiddle.net/DoomHamster/LhJsL/ 1/

另外,当单击没有默认单击事件的元素时,您不需要“return false”。

编辑:从您下面的评论中,我怀疑您首先在加载 jQuery 和 jQueryUI 时遇到问题。尝试用以下内容替换脚本和 css 链接作为测试,以消除路径问题:

<link type="text/css" rel="Stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/ui-lightness/jquery-ui.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>

Just take the 'open' out of your $('#Dialog').dialog('open'); and you are good to go.

Edit: Added this jsFiddle with your code as an example:

http://jsfiddle.net/DoomHamster/LhJsL/1/

Also, you don't need 'return false' when clicking an element with no default click event.

EDIT: From your comment below I suspect that you are having issues with loading jQuery and jQueryUI in the first place. Try replacing your script and css links with the following as a test to eliminate path issues:

<link type="text/css" rel="Stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/ui-lightness/jquery-ui.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
岁月无声 2025-01-15 12:23:56

试试这个

$(function()
{
    $('#dialog_link').click(function(){
    $('#Dialog').dialog();  
   return false;
    });
})

Try this

$(function()
{
    $('#dialog_link').click(function(){
    $('#Dialog').dialog();  
   return false;
    });
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文