欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在js(jquery)中獲得文本框焦點(diǎn)和失去焦點(diǎn)的方法

 更新時(shí)間:2012年12月04日 21:37:58   作者:  
文章介紹兩個(gè)方法和種是利用javascript onFocus onBlur來判斷焦點(diǎn)和失去焦點(diǎn),加一種是利用jquery $("p").blur(); 或$("p").blur(fn)來實(shí)現(xiàn),有需要的朋友可以參考一下

先來看javascript的直接寫在了input上

復(fù)制代碼 代碼如下:

<input name="pwuser" type="text" id="pwuser" class="input" value="樓盤賬號" onBlur="if(this.value=='') this.value='樓盤賬號';" onFocus="if(this.value=='樓盤賬號') this.value='';" />
<input name="pwpwd" type="password" class="input1" value="******" onBlur="if(this.value=='') this.value='******';" onFocus="if(this.value=='******') this.value='';">

jquery實(shí)現(xiàn)方法

對于元素的焦點(diǎn)事件,我們可以使用jQuery的焦點(diǎn)函數(shù)focus(),blur()。

focus():得到焦點(diǎn)時(shí)使用,和javascript中的onfocus使用方法相同。
如:
復(fù)制代碼 代碼如下:

$("p").focus(); 或$("p").focus(fn)

blur():失去焦點(diǎn)時(shí)使用,和onblur一樣。
如:
復(fù)制代碼 代碼如下:

$("p").blur(); 或$("p").blur(fn)

實(shí)例
復(fù)制代碼 代碼如下:

<form>
<label for="searchKey" id="lbSearch">搜神馬?</label> 這里label覆蓋在文本框上,可以更好的控制樣式
<input id="searchKey" type="text" />
<input type="submit" value="搜索" />
</form>

jquery代碼
復(fù)制代碼 代碼如下:

$(function() {
$('#searchKey').focus(function() {
$('#lbSearch').text('');
});
$('#searchKey').blur(function() {
var str = $(this).val();
str = $.trim(str);
if(str == '')
$('#lbSearch').text('搜神馬?');
});
})

好了相當(dāng)?shù)牟诲e(cuò)吧

相關(guān)文章

最新評論