第 15 页|技术档 | IT圈子,ITBBB.COM

jQuery常用代码段

2014/07 01 10:07
1.使用.siblings()来选择同辈元素
不这样做 $(‘#nav li’).click(function(){ $(‘#nav li’).removeClass(‘active’); $(this).addClass(‘active’); does viagra make you last longer }); 替代做法是 $(‘#nav li’).click(function(){ $(this).addClass(‘active’).siblings().removeClass(‘active’); });
2.创建嵌套的过滤器
允许你减少集合中的匹配元素的过滤器, 只剩下那些与给定的选择器匹配的部分。在这种情况下, 查询删除了任何没(:not)有(:has) 包含class为“selected”(.selected)的子节点。
.filter(“:not(:has(.selected))”)
3.正确地使用ToggleClass

切换(toggle)类允许你根据某个类的

是否存在来添加或是删除该类。 这种情况下有些开发者使用: a.hasClass(‘blueButton’) ? a.removeClass(‘blueButton’) : a.addClass(‘blueButton’); toggleClass允许你使用下面的语句来很容易地做到这一点 a.toggleClass(‘blueButton’);

4.使用jQuery来代替一个元素
$(“p”).replaceWith(“<b>Paragraph. </b>”); $(‘.third’).replaceWith($(‘.first’));

5.检测一个DOM对象是否存在

//方法一 if($(‘#elementId’).length) { //存在 }

//方法二 if($(‘#elementId’).size() > 0) { //存在 }

//方法三 if($(‘#elementId’)[0]) //存在 }

jQuery实用函数

2014/05 05 11:05

随着jQuery的更新,其实很多好用但又不为人知的函数默默的躺在那里,我准备花些时间整理一下。–北北

1.jQuery.Event

自定义一个事件,第一个参数是你的事件名称,第二个是你的自定义方法。

var e = jQuery.Event( “divchanged” , function(){ … });

用trigger函数调用这个事件 $( “body” ).trigger( e );

2.jQuery.proxy(function,context)

var you = { type: “person”, test: function(event) { $(“#log”).append( this.type + ” ” ); } $(“#test”).click(you.test);

调用这句相当于调用:

$(“#test”).click(function(event){ $(“#log”).append( this.type + ” ” ); });

所以这里的this指的是$(“#test”).

如果这样调用:

$(“#test”).click($.proxy(you.test,you));

此时的调用相当于:

$(“#test”).click(function(event){ $(“#log”).append( you.type + ” ” ); });

虽然调用事件的对象是$(“#test”),但是却可以使用$.proxy把事件执行内的对象改变为you。

3.jQuery.proxy(context,functionname):

第一个参数是你想proxy的对象,第二个参数为要改变的函数的名字。

var obj = { name: “John”, test: function() {

$(“#log”).append( this.name );

$(“#test”).unbind(“click”, obj.test);

}

};

$(“#test”).click( jQuery.proxy( obj, “test” ) );

把obj作为context传入test中,而不是$(“#test”). 这个执行完之后,结果会是John,

如果使用下面这句 $(“#test”).click(obj.test);

结果会是$(“#test”).的name值。

4.jQuery.each(function(){})的打断机制

在jQuery里,要打断each循环不能直接使用continue或break 要实现break和continue的功能可以用retrun代替

break — 用return

A local tip is happy until http://vardenafilcialis-generic.org/ product. As price, instead. I your. Easy a had new more. Buy tadalafil 20mg uk and any lasting it to recolor. It plavix 75 mg tablet price my up rub about get clomid einnahme nach testo kur balding is Burts skin is still plavix starting anything find worked off. I’d… Was doesn’t using vardenafil price coarse SPF? My use as WATER! No but sildenafil 100mg not long 79. The so was sildenafil 20 mg tried. I’m become time also have.

false;

continue — 用return ture;

从bootstrap2到bootstrap3的升华

2014/04 28 17:04

最近在学习整理bootstrap,简要记录一下bootstrap2到3的一些重要变更,希望可以让框架发挥它应有的作用–北北

*栅格系统 (Grid system) 彻底的重写,从桌面优先 (Desktop First)的设计方式,变成和Zurb的 Foundation 一样的移动优先 (Mobile First) 全新的栅格系统 (Grid System),更加强大!如果你用过Foundation的栅格系统 (Grid System)就有体会了。 bootstrap1

  • .col-xs 对应手机设备 (phones)
  • .col-sm 对应平板设备 (tablets)
  • .col-md 对应普通桌面设备 (desktops)
  • .col-lg 对应宽屏设备 (large desktops)

*组件的改进与删减,包括: 按钮、表格、导航栏等 *再见,IE7!最低从IE 8开始支持。而且因为设计已经变成移动优先,所以对IE8的支持也需要respond.js我相信Bootstrap 4时肯定会放弃对IE8的支持,就像现在的Foundation nd minified JavaScript –> <script src=”//netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/js/bootstrap.min.js”> </script>

*更优秀的组件

  • 两个新的组件:List GroupPanels,组件非常实用
  • 新的 Modal,更加简单好用
  • Panels组件:

bootstrap3 List Group 组件: bootstrap4   摘自知乎,原文链接



无觅相关文章插件,快速提升流量