类型错误: $(..).Live 不是 MVC 中的函数

TypeError: $(...).live is not a function in MVC

本文关键字:MVC 不是 函数 Live 错误 类型      更新时间:2023-09-26

我在MVC表单中使用了使用Jquery的对话框。

在我看来:

 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
 <script>
     $(function () {
         $("#dialog").dialog({
             autoOpen: false,
             show: {
                 effect: "blind",
                 duration: 1000
             },
             hide: {
                 effect: "explode",
                 duration: 1000
             }
         });
         $("#opener").click(function () {
             $("#dialog").dialog("open");
         });
     });
</script>
@using (Html.BeginForm())
{ 
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="opener">Open Dialog</button>
}

我尝试使用Firebug进行调试,它显示了错误

TypeError: $(...).live is not a function

$("a[data-ajax=true]").live("click", function (evt) {

当我单击该按钮时,jquery 函数将执行,但它不显示对话框。如何解决此问题?

使用 on 而不是 live,因为您使用的是 jQuery 1.10.2,在此版本中,不推荐使用 live 方法:

$("a[data-ajax=true]").on("click", function (evt) {