简体   繁体   English

如果前面的函数失败,如何防止jQuery函数无法运行?

[英]How to prevent jQuery functions from not running if a preceding function fails?

I'm having an issue with jQuery functions not running if a preceding function failed for example: 我有一个问题,如果前面的函数失败,jQuery函数没有运行,例如:

jQuery(function($) {
    // this function failed to run because the dependency file wasn't loaded
});


jQuery(function($) {
    // fails to run unless all preceding function succeed
});


jQuery(function($) {
    // fails to run unless all preceding function succeed
});

I'm doing this because they're all small chunks of code, each one for a jquery plugin used on my site so one for a slider another one for a drop down menu ..., for example if a page without a slider I'm not loading the slider plugin so all everything after the slider function fails to run. 我这样做是因为它们都是小块的代码,每个代码用于我的网站上使用的jquery插件,所以一个用于滑块另一个用于下拉菜单...,例如,如果没有滑块的页面我我没有加载滑块插件,因此滑块功能之后的所有内容都无法运行。

so what should I do so jquery ignores failing function ? 那么我应该怎么做才能让jquery忽略失败的功能?

and thanks in advance. 并提前感谢。

使用catch块来捕获错误,或者首先使用if以避免错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM