[英]HTML , Display IDs of every Text boxes , when I make focus
At my web page, I have several text box controls (eg. Input type="text" ...) What I would like to do is display every ID for every text box whenever or whatever text box i make focus event. 在我的网页上,我有几个文本框控件(例如,输入类型=“文本”...)我想做的是每当我做焦点事件的任何文本框时,显示每个文本框的每个ID。
I already try this. 我已经试过了。
alert($("*:focus").attr("id"));
But it return undefined message. 但它返回未定义的消息。
So, Please let me know is there any way to know that which text box, i mean text box ID, is I already focused dynamically. 所以,请让我知道有没有办法知道哪个文本框,我的意思是文本框ID,我已经动态集中。
Setting a variable on focus, and removing the variable on blur will do the job: 在焦点上设置变量,并在模糊上删除变量将完成工作:
var currentFocus = null; //to be defined in the global scope, if you want
// to access this property across your whole script
$("input").focus(function(){
currentFocus = this.id;
}).blur(function(){
currentFocus = null;
});
You may need to look if it has an ID or not. 您可能需要查看它是否具有ID。 I made an example: http://jsbin.com/opocoz/2/edit
我做了一个例子: http : //jsbin.com/opocoz/2/edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.