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.
I already try this.
alert($("*:focus").attr("id"));
But it return undefined message.
So, Please let me know is there any way to 开发者_Go百科know that which text box, i mean text box ID, is I already focused dynamically.
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. I made an example: http://jsbin.com/opocoz/2/edit
精彩评论