我试图在标签文本更改时触发一个函数。这是我的代码
$("#frameItemCode").change(function (e) {
alert("Changed");
});
#frameItemCode
是我的标签 ID,但事件未触发。我已经尝试过之前给出的示例,但它们对我没有帮助。这是我的 html
<div class="input-group">
<span class="input-group-addon" @*style="width: 120px;"*@>Item Group</span>
<label class="input-group-addon" @*style="width: 120px;"*@ id="frameGroupCode"></label>
<input class="form-control" type="text" id="frameGroupName" style="">
</div>
最佳答案
看看 documentation for the change
event .它只针对特定类型的元素触发:
The change event is fired for
<input>
,<select>
, and<textarea>
elements when a change to the element's value is committed by the user...
您将无法使用 change
不是前面提到的类型之一的元素的事件。
如果您有其他方式知道特定元素的编辑已完成,则必须触发您自己的事件 - 可能使用 blur
event在用于更改值的元素上。 blur
当所选元素失去焦点时触发事件,例如当用户单击(或标签)输入元素时。
关于javascript - 如何在标签文本更改时触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27635600/