打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JQuery必会5个小技巧

JQuery是个不错的框架,以下总结了5个每个网站开发者都应该知道的小技巧:

 

1.禁用右键菜单

 

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});

 

2.让字体闪烁

 

jQuery.fn.flash = function( color, duration )
{
    var current = this.css( 'color' );
    this.animate( { color: 'rgb(' + color + ')' }, duration / 2 );
    this.animate( { color: current }, duration / 2 );
}
 
$( '#someid' ).flash( '255,0,0', 1000 );

 

3.准备文档替换方案

 

$(function(){
	//document is ready do something
});

 

4.检测browser

 

// Safari
if( $.browser.safari )
{
//do something
}
 
//Above IE6
if ($.browser.msie && $.browser.version > 6 )
{
//do something
}
 
// IE6 and below
if ($.browser.msie && $.browser.version <= 6 )  { //do something } // Firefox 2 and above if ($.browser.mozilla && $.browser.version >= "1.8" )
{
//do something
}

 

5.检查存在的元素

 

if ($("#someDiv").length) {
    //yes it does ,do something
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
jQuery 1.4实用技巧大放送
jquery26个技巧
对jQuery的事件绑定的一些思考(补充)
编写一个jquery插件
一段原生JS获取浏览器类型、版本的代码
jQuery中对未来的元素绑定事件用bind、live or on
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服