简体   繁体   English

当我进行焦点时,HTML,显示每个文本框的ID

[英]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.

相关问题 如何使FormPanel中的数据显示为文本而不是输入框? - How can I make the data in a FormPanel display as text instead of in input boxes? 我想每当HTML文本输入字段中的数据发生更改时就触发一次事件,而与焦点无关 - I want to trigger an event every single time data changes in an HTML text input field regardless of focus 失去焦点时更改显示文本 - Change display text when focus is lost 将文本区域的输入显示为 HTML 并将 ID 分配给 HTML 元素 - Display input from text area as HTML and assign IDs to the HTML elements 当焦点显示在搜索文本上时,scrollTop不起作用? - scrollTop not work when focus is display on search text? Javascript,当在文本框中放置答案时,如何使复选框成为必需 - Javascript, how can i make tick boxes required when an answer is placed in a text box 当我单击html表中的“编辑”时,如何发送这些详细信息同一页文本框以在jsp中进行更新 - When i click edit in html table how to send those details same page text boxes to update in jsp eventListner在另一个文本框获得焦点时添加文本框(香草js) - eventListner to add a text boxes when another text box gets focus (vanilla js) 如何向文本框添加动态 ID? - How to add dynamic ids to text boxes? 如何使html中的单选框看起来像复选框,并在选中时使其带有x? - How can I make the radio boxes in html look like checkboxes and make them have x's when checked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM