Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 理解jQuery'$(函数(){…})';逻辑_Asp.net Mvc 3_Jquery_Partial Views - Fatal编程技术网

Asp.net mvc 3 理解jQuery'$(函数(){…})';逻辑

Asp.net mvc 3 理解jQuery'$(函数(){…})';逻辑,asp.net-mvc-3,jquery,partial-views,Asp.net Mvc 3,Jquery,Partial Views,我在ASP.NET MVC 3中有一个部分视图,其中包含一个脚本: <script type="text/javascript" > $(function () { $("#tagbox").autocomplete({ source: "/Tag/GetTags", minLength: 1, select: function (event, ui) {

我在ASP.NET MVC 3中有一个部分视图,其中包含一个脚本:

<script type="text/javascript" >
    $(function () {
        $("#tagbox").autocomplete({
            source: "/Tag/GetTags",
            minLength: 1,
            select: function (event, ui) {
                $("tagbox").val(ui.item.value);
            }
        });
    });
    </script>
但是,当通过访问URL将其加载为新视图时,一切正常

我的主要观点中也有这些参考:

<script src="http://static.jsbin.com/js/prod/jsbin-3.4.4.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>


其次,当我更改引用之间的顺序时,我的ajax调用将作为一个新视图打开,而不是部分视图。也许其中有一个是不必要的,或者其他什么?

请按照下面的链接,它将清楚地解释jquery$(function(){}


“第二,…”更改顺序实际上可能会由于缺少依赖项而导致错误,具体取决于您所做的更改。至于您的主要问题,请删除
$(function(){})
不应该神奇地让某些东西开始工作,尽管如果它没有它就可以工作,那么首先就没有理由拥有它。拥有
$(function(){})是没有意义的
在使用ajax加载的代码中,虽然有它不应该影响代码是否成功运行。感谢您的回答。您能简单解释一下为什么在使用ajax加载的代码中使用$(function(){})没有意义吗?$(function(){})执行function(){}在DOM准备好之后,ajax调用不太可能在DOM准备好之前完成。
<script src="http://static.jsbin.com/js/prod/jsbin-3.4.4.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>