读书人

jquery日志

发布时间: 2012-09-03 09:48:39 作者: rapoo

jquery日记
1.元素选择器的第二个参数的作用是限定查找范围,如
$('div.wp-caption').each(function(i) {
var img_ = $('img', this);
});

2.选择器拥有获取和设置元素的盒模型属性的方法,如
var p_height = $('p', this).outerHeight();

3.事件切换:
hover事件可以有两个回调函数,分别是鼠标移入和移除的效果;而click只有一个,如

$(this).hover(function() {
img_.animate({marginTop : -p_height}, 500);
}, function() {
img_.animate({marginTop : '0'}, 500);
});

4.网页打开,输入框自动获取焦点
<body onload='document.getElementById("name").focus()'>
<h2>定向地区</h2>
<input id="name" name="name" type="text">
</body>

读书人网 >Web前端

热点推荐