如何对所使用的特定 jQuery(和 Javascript)方法/函数进行功能检测/测试
大家好,希望你们都做得很棒,
我对 javascript 和 jquery 很陌生,我(认为)我在我正在工作的网站上想出了一个简单的淡入/淡出实现(查看 http://www.s5ent.com/expandjs.html - 如果您有时间检查它是否效率低下或什么那真是太甜蜜了)。我使用以下函数/方法/集合,我想在使用它们之前进行功能测试。嗯..怎么样?或者有更好的方法来解决这个问题吗?
jQuery
$
.fadeIn([duration])
.fadeOut([duration])
.attr(attributeName,value)
.append(content)
.each(function(index,Element))
.css(propertyName,value)
.hover(handlerIn(eventObject),handlerOut(eventObject))
.stop([clearQueue],[jumpToEnd])
.parent()
.eq(index)
JavaScript
setInterval(expression,timeout)
clearInterval(timeoutId)
setTimeout(expression,timeout)
clearTimeout(timeoutId)
我尝试研究 jquery.support 的 jquery,但我发现自己遇到了概念问题,即淡入/淡出,我(认为我)应该测试 $.support.opacity,但这在 ie 中是错误的,而 ie6+ 仍然可以公平地渲染淡入淡出。
我也在使用jquery 1.2.6,因为这足以满足我的需要。支持对象在1.3中。所以我希望尽可能避免拖入更多不必要的代码。
我也从事过浏览器嗅探工作,无论多么令人不悦。但这对我来说也是一个更大的问题,因为非标准的 ua 字符串和欺骗以及其他我不知道的事情。
那么你们认为我应该怎么做呢?或者我应该吗?有没有更好的方法来确保我不会运行最终会破坏页面的代码?我已经将其设置为当 javascript 不存在时降级为 css 悬停..
需要专业知识。非常感谢,谢谢家伙!
good day everyone, hope yer all doin awesome
am very new to javascript and jquery, and i (think) i have come up with a simple fade-in/out implementation on a site am workin on (check out http://www.s5ent.com/expandjs.html - if you have the time to check it for inefficiency or what that'd be real sweet). i use the following functions/methods/collections and i would like to do a feature test before using them. uhm.. how? or is there a better way to go about this?
jQuery
$
.fadeIn([duration])
.fadeOut([duration])
.attr(attributeName,value)
.append(content)
.each(function(index,Element))
.css(propertyName,value)
.hover(handlerIn(eventObject),handlerOut(eventObject))
.stop([clearQueue],[jumpToEnd])
.parent()
.eq(index)
JavaScript
setInterval(expression,timeout)
clearInterval(timeoutId)
setTimeout(expression,timeout)
clearTimeout(timeoutId)
i tried looking into jquery.support for the jquery ones, but i find myself running into conceptual problems with it, i.e. for fadein/fadeout, i (think i) should test for $.support.opacity, but that would be false in ie whereas ie6+ could still fairly render the fades.
also am using jquery 1.2.6 coz that's enough for what i need. the support object is in 1.3. so i'm hoping to avoid dragging-in more unnecessary code if i can.
i also worked with browser sniffing, no matter how frowned-upon. but that's also a bigger problem for me because of non-standard ua strings and spoofing and everything else am not aware of.
so how do you guys think i should go about this? or should i even? is there a better way to go about making sure that i don't run code that'll eventually break the page? i've set it up to degrade into a css hover when javascript ain't there..
expertise needed. much appreciated, thanks guyz!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用以下命令检查 jquery 函数是否可用,例如用于追加:
这对于检查是否已安装代码所依赖的插件非常有用。
Use the following to check whether a jquery function is available, eg for append:
This is useful checking to see if plugins have been installed that your code depends on.