标签文本更改时如何触发事件 [英] how to fire event on label text change

查看:238
本文介绍了标签文本更改时如何触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在标签文本更改时触发一个函数.这是我的代码

I'm trying to fire a function when the label text changes. This is my code

$("#frameItemCode").change(function (e) {
    alert("Changed");
});

#frameItemCode是我的标签ID,但未触发该事件.我曾经尝试过给出的示例,但它们并没有帮助我.这是我的html

#frameItemCode is my label id, but the event isn't firing. I have tried examples given before but they hasn't helped me.This is my 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>

推荐答案

看看 change事件的文档.它仅针对特定类型的元素触发:

Take a look at the documentation for the change event. It only fires for specific types of elements:

当用户提交对元素的值的更改时,将触发<input><select><textarea>元素的change事件...

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事件.

You won't be able to use the change event for an element that is not one of the previously mentioned types.

如果您还可以通过其他方式知道特定元素的编辑已完成,则必须触发您自己的事件-可能使用

If you have some other way of knowing that editing has finished of a specific element, you'll have to fire your own event - possibly using the blur event on the element that was used to change the value. The blur event is triggered when the selected element looses focus such as when a user clicks (or tabs) out of an input element.

这篇关于标签文本更改时如何触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆