Modernizr测试 [英] Modernizr testing

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

问题描述

为什么会同时发出警告,是和否?

How come this alerts both, yes and false?

Modernizr.load([
    {
        test: Modernizr.cssgradients,
        yep: alert('Supports it!'),
        nope: alert('Oh, damn! This browser sucks!')
    }
]);

我在OS X上使用最新的Chrome。

I'm using the latest chrome on OS X.

推荐答案

因为您直接在那里调用 alert(),并且警报的结果()(总是 undefined )被分配给是的 nope 属性。您需要在函数中包装 alert()并改为分配该函数:

Because you're calling alert() directly there, and the result from alert() (always undefined) is assigned to the yep and nope properties. You need to wrap alert() in a function and assign that function instead:

Modernizr.load([
    {
        test: Modernizr.cssgradients,
        yep: function () { alert('Supports it!') },
        nope: function () { alert('Oh, damn! This browser sucks!') }
    }
]);

这个仍然不起作用,因为它不是如何 yepnope 有效。 yep nope 应该是加载的JS文件的路径:

This still won't work because it's not how yepnope works. yep and nope should be paths to JS files that are loaded:

Modernizr.load([
    {
        test: Modernizr.cssgradients,
        nope: 'cssgradients-shim.js'  //-> load a JS file to draw your gradients
    }
]);

正如您自己发现的那样,如果您不想使用集成的yepnope.js,您可以只需使用Modernizr 传统方式

As you discovered yourself, if you don't want to use the integrated yepnope.js, you can just use Modernizr the traditional way:

if (!Modernizr.cssgradients) {
    alert('Oh, damn! This browser sucks!');
}

这篇关于Modernizr测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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