jquery获取焦点事件,jQuery获取焦点

jquery一个div怎么获得焦点和失去焦点

DIV获取焦点(两种方法):

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、成都微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了黄平免费建站欢迎大家使用!

DIV直接使用focus()和blur()两个方法是无效的,需添加tabindex="0"或者contenteditable="true"属性

①:设置div为可编辑状态,则可点击获取焦点,同时div的内容也是可以编辑的;如:

div

contenteditable="true"11111111111111/div

②:设置div的tabindex,此时div的内容是不可编辑的;如:

div

tabindex="0"11111111111111/div

PS:设置tabindex属性,按键盘Tab键可让其获取焦点,其中tabindex的值越小在tab键切换的时候就会首先聚焦

js jQuery 触发获取焦点

$('input[name="name"]').on('input propertychange', function(event) {

var _this = $(this);

var vals = _this.val();

if(vals!=''){

setTimeout(function(){

_this.next().focus();

},1000)

}

});

jquery获取焦点问题

script type="text/javascript"

$(function() {

// 点击 "弹出层" 在页面建立 div 层

$("#open").on("click", function() {

$("body").append('div id="popup" style="width: 100px; height: 100px; background: #eee; padding: 20px;"p文字文字文字/pinput type="button" id="ok" value="确定" /input type="button" id="cancel" value="取消" //div');

// 确认 按钮获取焦点

$("#ok").focus();

});

$(document).on("click", "#ok", function() {

alert("通过点击 确定 关闭层");

$("#popup").remove();

}).on("click", "#cancel", function() {

alert("通过点击 取消 关闭层");

$("#popup").remove();

}).on("keydown", function(e) {

if(e.which === 13) {

alert("通过键盘 回车 关闭层");

$("#popup").remove();

}

else if(e.which === 27) {

alert("通过键盘 ESC 关闭层");

$("#popup").remove();

}

});

});

/script

input type="button" id="open" value="弹出层" /

你可以根据不同事件(鼠标点击 确认/取消,键盘按下 回车/ESC)在 .remove() 之前添加更多代码。

jquery js 当文本框获得焦点时,自动选中里面的文字

$(function(){

$(":text").focus(function(){

this.select();

});

});

JQuery文本框获得焦点背景颜色改变:

1.先使用jQuery选择器找到所有的文本框。

2.为文本框注册获得焦点事件,即focus事件。

3.在焦点事件的事件处理函数中对当前得到焦点的文本框设置背景色。

4.注册失去焦点事件,即blur事件。

5.在失去焦点的事件处理函数中对当前触发事件的文本框改变背景颜色。

script type="text/javascript"

$(function(){

//找到文本框,并注册得到焦点事件。

$("input:text").focus(function(){

//让当前得到焦点的文本框改变其背景色。

$(this).css("background","pink");

});

//找到文本框,并注册失去焦点事件

$("input:text").blur(function(){

//让当前失去焦点的文本框背景色变为白色。

$(this).css("background","white");

});

});

/script


分享标题:jquery获取焦点事件,jQuery获取焦点
地址分享:http://ybzwz.com/article/dsdejoe.html