1、jQuery中 append() 和 appendTo() 的 区别:
- 都是在某元素内部插入
- append 在xxx元素内部插入xxx
- appendTo 把xxx插入xxx元素
代码如下
$('.iphone').append(h5);
$(h5).appendTo('.iphone');
2、如何给某一个元素设置一个id?
var id = ('h5_c_' + Math.random()).replace('.', '_')
Math.random()-->获取随机数,replace,替换。
3、改变宽度和高度的方法:
cfg.width && component.width(cfg.width/2);
cfg.height && component.height(cfg.height/2);
4、为元素设置背景图片
cfg.bg && component.css('backgroundImage', 'url(' + cfg.bg + ')');
注意:1、Image要驼峰写法 2、拼接ur
5、jquery中的animate
cfg.animateOut && component.animate( cfg.animateOut );
6、jQuery中的click方法function在括号里面,需要注意de
$("button").click(function(){
$("p").slideToggle();
});
7、如何写链式调用?
关键点1:第四行和第八行的return this
关键点2:
记录最后一个page。
jQuery中的隐藏 .hide()
8、jQuery中slice的用法
.slice(selector,end)
参数 | 描述 |
---|---|
selector | 基于 0 的整数值,指示开始选取元素的位置。 如果是负数,则指示从集合末端开始的偏移量。 |
end | 基于 0 的整数值,指示结束选取元素的位置。 如果是负数,则指示从集合末端开始的偏移量。 如果省略,则选取范围会在集合末端结束。 |
9、$.each(): 用来遍历数组
$(function () {
$.each([52, 97], function(index, value) {
alert(index + ': ' + value);
});
})