$(document).ready(function() {//Example 1: Every link will open in a new window
$('a[href^="http://"]').attr("target", "_blank");
//Example 2: Links with the rel="external" attribute will only open in a new window
$('a[@rel$='external']').click(function(){this.target = "_blank";
});
});
// use
<a href="http://www.opensourcehunter.com" rel=external>open link</a>
3.判读浏览器类型
$(document).ready(function() {// Target Firefox 2 and aboveif ($.browser.mozilla && $.browser.version >= "1.8" ){
// do something
}
// Target Safariif( $.browser.safari ){
// do something
}
// Target Chromeif( $.browser.chrome){
// do something
}
// Target Caminoif( $.browser.camino){
// do something
}
// Target Operaif( $.browser.opera){
// do something
}
// Target IE6 and belowif ($.browser.msie && $.browser.version <= 6 ){
// do something
}
// Target anything above IE6if ($.browser.msie && $.browser.version > 6){
// do something
}
});
$(document).ready(function() {
$.extend($.expr[':'], {
moreThen500px: function(a) {return $(a).width() > 500;
}
});
$('.box:moreThen500px').click(function() {// creating a simple js alert box
alert('The element that you have clicked is over 1000 pixels wide');
});
});