jQuery¼¼Êõ

ÔÚjs(jquery)ÖлñµÃÎı¾¿ò½¹µãºÍʧȥ½¹µãµÄ·½·¨

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2015-10-23 18:06 ÎÒÒªÆÀÂÛ( )

ÎÄÕ½éÉÜÁ½¸ö·½·¨ºÍÖÖÊÇÀûÓÃjavascript onFocus onBlurÀ´ÅжϽ¹µãºÍʧȥ½¹µã£¬¼ÓÒ»ÖÖÊÇÀûÓÃjquery $(p).blur(); »ò$(p).blur(fn)À´ÊµÏÖ£¬ÓÐÐèÒªµÄÅóÓÑ¿ÉÒԲο¼Ò»

ÏÈÀ´¿´javascriptµÄÖ±½ÓдÔÚÁËinputÉÏ

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


<input type="text" value="Â¥ÅÌÕ˺Å" onBlur="if(this.value=='') this.value='Â¥ÅÌÕ˺Å';" onFocus="if(this.value=='Â¥ÅÌÕ˺Å') this.value='';" />
<input type="password" value="******" onBlur="if(this.value=='') this.value='******';" onFocus="if(this.value=='******') this.value='';">


jqueryʵÏÖ·½·¨

¶ÔÓÚÔªËصĽ¹µãʼþ£¬ÎÒÃÇ¿ÉÒÔʹÓÃjQueryµÄ½¹µãº¯Êýfocus(),blur()¡£

focus()£ºµÃµ½½¹µãʱʹÓ㬺ÍjavascriptÖеÄonfocusʹÓ÷½·¨Ïàͬ¡£
È磺

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


$("p").focus(); »ò$("p").focus(fn)


blur()£ºÊ§È¥½¹µãʱʹÓ㬺ÍonblurÒ»Ñù¡£
È磺

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


$("p").blur(); »ò$("p").blur(fn)


ʵÀý

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


<form>
<label for="searchKey">ËÑÉñÂí£¿</label> ÕâÀïlabel¸²¸ÇÔÚÎı¾¿òÉÏ£¬¿ÉÒÔ¸üºÃµÄ¿ØÖÆÑùʽ
<input type="text" />
<input type="submit" value="ËÑË÷" />
</form>


jquery´úÂë

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


$(function() {
$('#searchKey').focus(function() {
$('#lbSearch').text('');
});
$('#searchKey').blur(function() {
var str = $(this).val();
str = $.trim(str);
if(str == '')
$('#lbSearch').text('ËÑÉñÂí£¿');
});
})


ºÃÁËÏ൱µÄ²»´í°É

Äú¿ÉÄܸÐÐËȤµÄÎÄÕÂ:

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
ÍøÓѵãÆÀ
×