jQuery開發(fā)者都需要知道的5個小技巧
更新時間:2010年01月08日 00:11:02 作者:
JQuery是個不錯的框架,以下總結(jié)了5個每個網(wǎng)站開發(fā)者都應(yīng)該知道的小技巧,都是一些非常不錯的,經(jīng)常能用得到的。
1.禁用右鍵菜單
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
2.讓字體閃爍
jQuery.fn.flash = function( color, duration )
{
var current = this.css( 'color' );
this.animate( { color: 'rgb(' + color + ')' }, duration / 2 );
this.animate( { color: current }, duration / 2 );
}
$( '#someid' ).flash( '255,0,0', 1000 );
3.準(zhǔn)備文檔替換方案
$(function(){
//document is ready do something
});
4.檢測browser
// Safari
if( $.browser.safari )
{
//do something
}
//Above IE6
if ($.browser.msie && $.browser.version > 6 )
{
//do something
}
// IE6 and below
if ($.browser.msie && $.browser.version <= 6 ) { //do something } // Firefox 2 and above if ($.browser.mozilla && $.browser.version >= "1.8" )
{
//do something
}
5.檢查存在的元素
if ($("#someDiv").length) {
//yes it does ,do something
}
復(fù)制代碼 代碼如下:
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
2.讓字體閃爍
復(fù)制代碼 代碼如下:
jQuery.fn.flash = function( color, duration )
{
var current = this.css( 'color' );
this.animate( { color: 'rgb(' + color + ')' }, duration / 2 );
this.animate( { color: current }, duration / 2 );
}
$( '#someid' ).flash( '255,0,0', 1000 );
3.準(zhǔn)備文檔替換方案
復(fù)制代碼 代碼如下:
$(function(){
//document is ready do something
});
4.檢測browser
復(fù)制代碼 代碼如下:
// Safari
if( $.browser.safari )
{
//do something
}
//Above IE6
if ($.browser.msie && $.browser.version > 6 )
{
//do something
}
// IE6 and below
if ($.browser.msie && $.browser.version <= 6 ) { //do something } // Firefox 2 and above if ($.browser.mozilla && $.browser.version >= "1.8" )
{
//do something
}
5.檢查存在的元素
復(fù)制代碼 代碼如下:
if ($("#someDiv").length) {
//yes it does ,do something
}
相關(guān)文章
JQuery的html(data)方法與<script>腳本塊的解決方法
在使用Jquery的html(data)方法執(zhí)行寫數(shù)據(jù)到Dom元素時遇到一個問題:在data參數(shù)中包含script腳本塊的時候,html(data)方法的執(zhí)行結(jié)果與預(yù)期不符2010-03-03jquery實現(xiàn)標(biāo)簽上移、下移、置頂
這篇文章主要介紹了jquery實現(xiàn)標(biāo)簽上移、下移、置頂?shù)南嚓P(guān)資料,并附上示例,非常實用,需要的朋友可以參考下2015-04-04jQuery中event.target和this的區(qū)別詳解
這篇文章主要介紹了jQuery中event.target和this的區(qū)別詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08ajax 提交數(shù)據(jù)到后臺jsp頁面及頁面跳轉(zhuǎn)問題
這篇文章主要介紹了ajax 提交數(shù)據(jù)到后臺jsp頁面及頁面跳轉(zhuǎn)問題的相關(guān)資料,需要的朋友可以參考下2017-01-01