基於jquery實現的移入頁面上空文字框時,讓它變為焦點,移出清除焦點

來源:互聯網
上載者:User

複製代碼 代碼如下:
var Page_INIT = function () {
$(document).bind("mouseover", function (e) {//滑鼠移入
if (e.target.tagName.toUpperCase() == "INPUT") {
var input = e.target;
if (input.type == "text") {//如果是文字框
if (window.Page_FocusTimer) {//如果處於焦點狀態
window.clearTimeout(window.Page_FocusTimer);//清除焦點狀態
}
window.Page_FocusTimer = window.setTimeout(function () { //每0.2豪秒去執行這個匿名方法一次
if (!input.value) {//如果內容為空白,則設為焦點
try {
input.focus();
} catch (e) { }
}
}, 200);
}
}
}).bind("mouseout", function (e) {//滑鼠移出
if (e.target.tagName.toUpperCase() == "INPUT") { //被處理的事件來源對象它的名稱(即HTML標記)轉為大寫後如果是INPUT
var input = e.target;
if (input.type == "text") {
if (window.Page_FocusTimer) {
window.clearTimeout(window.Page_FocusTimer);
}
}
}
});
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.