This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* IE 6 */ | |
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 6]><i></i><![endif]-->"; | |
var isIE = checkIE.getElementsByTagName("i").length == 1; | |
/* IE 7 */ | |
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 7]><i></i><![endif]-->"; | |
var isIE = checkIE.getElementsByTagName("i").length == 1; | |
navigator.appVersion.indexOf("MSIE 7.")!=-1 | |
/* IE 8 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('textarea').bind('input propertychange', function() { | |
$('.msg').html($(this).val().length + ' characters'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery 实现的内部链接平滑滚动 | |
$('a[href^="#"]').bind('click.smoothscroll', function(e) { | |
e.preventDefault(); | |
var anchor = this.hash; | |
var $target = $(target); | |
$('html, body').stop().animate({ | |
'scrollTop': $target.offset().top | |
}, 500, 'swing', function() { | |
window.location.hash = anchor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery 处理所有节点文本 | |
$('#elem').contents().each(function() { | |
if(this.nodeType === 3 && $.trim($(this).text())) { | |
$(this).wrap(''); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery 限制选择框选择个数 | |
$("#categories option").click(function(e) { | |
if ($(this).parent().val().length < 2) { | |
$(this).removeAttr("selected"); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery 平滑回到顶端链接 | |
$(function() { | |
$("a.gotop").click(function() { | |
$("html, body").animate({ | |
scrollTop: $($(this).attr("href")).offset().top + "px" | |
}, { | |
duration: 500, | |
easing: "swing" | |
}); | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery 处理图片尺寸 | |
$(window).bind("load", function() { | |
$('#imglist img').each(function() { | |
var maxWidth = 120; | |
var maxHeight = 120; | |
var ratio = 0; | |
var width = $(this).width(); | |
var height = $(this).height(); | |
if (width > maxWidth) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery 测试密码强度 | |
$('#pass').keyup(function(e) { | |
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$", "g"); | |
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g"); | |
var enoughRegex = new RegExp("(?=.{6,}).*", "g"); | |
if (false == enoughRegex.test($(this).val())) { | |
$('#passstrength').html('More Characters'); | |
} else if (strongRegex.test($(this).val())) { | |
$('#passstrength').className = 'ok'; | |
$('#passstrength').html('Strong!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var maxHeight = 0; | |
$("div").each(function() { | |
if ($(this).height() > maxHeight) maxHeight = $(this).height(); | |
}); | |
$("div").height(maxHeight); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery 实现的 Facebook 风格的图片预加载效果 | |
var preloadimg = "preload.jpg"; | |
$(function() { | |
window.setTimeout(function() { | |
var img = $("<img>").attr("src", preloadimg).load(function() { | |
$('div').append(img); | |
}); | |
}, 100); | |
}); |
OlderNewer