Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.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
MVC4.0JavaScript不';行不通_Javascript_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

MVC4.0JavaScript不';行不通

MVC4.0JavaScript不';行不通,javascript,asp.net-mvc,asp.net-mvc-4,Javascript,Asp.net Mvc,Asp.net Mvc 4,获取了一个移动应用程序,并希望运行javascript。将脚本(“startstop”)放在捆绑包中: public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-1.*")); bundle

获取了一个移动应用程序,并希望运行javascript。将脚本(“startstop”)放在捆绑包中:

    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-1.*"));

        bundles.Add(new ScriptBundle("~/bundles/startstop").Include(
                    "~/Scripts/startstop*"));
    ...
将捆绑包包括在视图中:

@section Scripts {
    @Scripts.Render("~/bundles/startstop")    
}
简化脚本:

$(document).ready(function () {
    alert('Hello');
});
当我运行页面/应用程序时,startstop脚本中的操作未被触发/执行(
IExporer/Chrome
)。但是,当我复制生成的页面的源代码(包括脚本和内容)并在
IExporer/Chrome
中打开保存(复制)的页面时,这个startstop脚本运行良好


有人知道怎么回事吗?提前感谢您的帮助

如果脚本文件名以.min.js结尾,它将被忽略。如果是这种情况,请尝试将其添加到RegisterBundles函数的顶部

bundles.IgnoreList.Clear();

编辑:已澄清。

不知道原因,但问题是由@section.Scripts引起的:

@section Scripts {
    @Scripts.Render("~/bundles/startstop")    
}
没有此部分,startstop脚本可以正常工作:

@Scripts.Render("~/bundles/startstop")
他做这项工作。 第一种情况的渲染与第二种情况略有不同:

    </div>
  </div>
<script src="/Scripts/jquery-1.7.2.js"></script>
<script src="/Scripts/jquery.mobile-1.1.0.js"></script>
<script src="/Scripts/jquery-1.7.2.js"></script>
<script src="/Scripts/startstop.js"></script>
</body></html>

而工作变量看起来像:

     <script src="/Scripts/jquery-1.7.2.js"></script>
     <script src="/Scripts/startstop.js"></script>
     </div>
  </div>
<script src="/Scripts/jquery-1.7.2.js"></script>
<script src="/Scripts/jquery.mobile-1.1.0.js"></script>
</body></html>


仍然让我困惑,但它有效

完整的脚本名是startstop.js您是否在局部视图中使用它?您是否在某个时候也引用了jquery?现在您已经给出了文件名,我可以复制这个好的文件,它可以工作了,包也可以了。因此,我可以看到剩下的两个选项是,您没有在global.asax中调用RegisterBundles方法,或者您没有引用jquery脚本。这是一个普通视图(不是部分视图)。应用程序_Start包含BundleConfig.RegisterBundles(BundleTable.Bundles);生成的页面引用jquery、jquery mobile和startstop脚本。$(document).ready通常是自动触发的。请确保您引用了Jquery,并且它位于此捆绑包的顶部。完整的脚本名称是startstop.js