分享五个有用的jquery小技巧

下文里技巧实现的效果虽然并不新鲜,但通过jQuery的封装,HTML实现了很大的清洁。清爽简洁又高效的代码任何时候都是开发者所醉心追求的终极目标,也许它简单,但是它能量巨大。一起来看看编程之家小编推荐给大家的五个非常实用的jQuery技巧。

1.禁用鼠标右键

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

当然jquery1.7版本以后bind()函数推荐用on()来代替。

2.让内容闪烁起来

rush:js;"> $.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',1000);

3.DOM加载完成的简写形式

rush:js;"> $(function() { // document is ready.. })

4.探测浏览器

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.判断元素是否存在

rush:vb;"> if($("#someDiv").length) { // yes it does,do something... }

以上跟大家分享了五个有用的jquery小技巧,希望大家喜欢。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...