jquery 觸發/失去焦點事件例子詳解

觸發焦點:javascript

$("Element").focus()css

觸發每個匹配元素得到焦點事件。java

$("Element").focus(function)jquery

事件會在得到焦點的時候觸發,既能夠是鼠標行爲,也能夠是按tab鍵導航觸發的行爲,而且綁定一個處理方法。.net


失去焦點:3d

$("Element").blur()htm

觸發每個匹配元素失去焦點事件。事件

$("Element").blur(function)ip

事件會在元素失去焦點的時候觸發,既能夠是鼠標行爲,也能夠是按tab鍵離開的行爲,而且綁定一個處理方法。get

例子一

代碼以下 複製代碼
$(document).ready(function(){
$(".regbox .textb").bind("focus",function(){});
$(".regbox .textb").bind("blur",function(){});
$("input").css({"background-colo(www.111cn.net)r":"#fff3de"});
//if (screen.width>=1280){}else if (screen.width<1280){}


})

例子二

代碼以下 複製代碼
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#username').focus(function ()//獲得教室時觸發的時間
{
$('#username').val('');
})
$('#username').blur(function () 失去焦點時觸發的時間
{
if ($('#username').val() == 'marry') {
$('#q').text('用戶名已存在!')
}
else { $('#q').text('ok!') }
})

from:http://www.111cn.net/wy/jquery/60507.htm

相關文章
相關標籤/搜索