类似于 undo 函数,用于返回到调用 find() 或 parents() 函数(或者其它遍历函数)之前的 jQuery 对象。
// hide all the labels inside the form with the ‘optional’ class
.find(’label.optional’).hide().end()
// add a red border to any password fields in the form
.find(’input:password’).css(’border’, ‘1px solid red’).end()
// add a submit handler to the form
.submit(function(){
return confirm(’Are you sure you want to submit?’);
});
所有空 td 加入 -
$(’td:empty’).html(’-');
非 class=”required” 隐藏
$(’input:not(.required)’).hide();
jquery show() hide() 函数
$(’ul, ol, dl’).hide();
table class=”stried” 下所有 odd(偶数)tr 背景色
$(’table.striped > tr:odd’).css(’background’, ‘#999999′);
jquery 插件例子
$.fn.background = function(bg){
return this.css(’background’, bg);
};
$(”body”).background(”#c00″)
可以使用 jQuery 处理基本的动画和显示效果。animate() 函数是动画代码的核心,它用于更改任何随时间变化的数值型的 CSS 样式值。比方说,您可以变化高度、宽度、不透明度和位置。还可以指定动画的速度,定为毫秒或者预定义的速度:慢速,中速或快速。
下面是一个同时变化某个元素高度和宽度的示例。请注意,这些参数没有开始值,只有最终值。开始值取自元素的当前尺寸。同时我也附加了一个回调函数。
$(’#grow’).animate({ height: 500, width: 500 }, “slow”, function(){
alert(’The element is done growing!’);
});
jQuery 的内置函数使更多常见的动画更容易完成。可以使用 show() 和 hide() 元素,立即显示或者以特定的速度显示。还可以通过使用 fadeIn() 和 fadeOut(),或者 slideDown() 和 slideUp() 显示和隐藏元素,这取决于您所需要的显示效果。下面的示例定义了一个下滑的导航菜单。
Leave a reply