JQuery.Validate CDN后备 [英] JQuery.Validate CDN fallback

查看:196
本文介绍了JQuery.Validate CDN后备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的后续步骤: 使用Google的托管jQuery的最佳方法,但在我的Google托管库上失败了

A bit of a follow on from this question: Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

因此,我可以检测JQuery CDN是否关闭并允许这样做:

So I can detect if the JQuery CDN is down and allow for this:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
        <script type="text/javascript">
            if (typeof jQuery == 'undefined') {
                document.write(unescape("%3Cscript src='/Script/jquery-1.7.2.min.js' type='text/javascript'%3E%3C/script%3E"));
            }
</script>

加载为:如何对jquery.validate进行相同操作

How do I do the same for jquery.validate, when loaded as:

<script type="text/javascript" language="javascript" src="http://ajax.microsoft.com/ajax/jQuery.Validate/1.6/jQuery.Validate.min.js"></script>

推荐答案

请改用此:

if(typeof $().validate == 'undefined')
{
    /// same code as before except pointing at your local jQuery.validate path
}

演示-检查是否存在验证

如果存在则在控制台中返回true,否则返回false. 删除DEMO中的脚本引用以将false作为输出.

DEMO - Check if validate exists

Returns true in the console if it exists and false if not.
Remove the script reference in the DEMO to get false as output.

您的完整代码可能类似于以下内容:

Your complete code may look similar to this:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery.Validate/1.6/jQuery.Validate.min.js"></script>

<script type="text/javascript">
    if (typeof jQuery == 'undefined') {
        document.write(unescape("%3Cscript src='/Script/jquery-1.7.2.min.js' type='text/javascript'%3E%3C/script%3E"));
    };

    if (typeof $().validate == 'undefined') {
        document.write(unescape("%3Cscript src='/Script/jquery.Validate-1.6.min.js' type='text/javascript'%3E%3C/script%3E"));
    }
</script>

这篇关于JQuery.Validate CDN后备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆