问题描述
我有 3 个文本框,它们都具有相同的 id,我通过将其放入控制器数组中处理到 ASP 中
I have 3 textboxes, all with the same id's that I process into ASP by bringing it into a controller array
我有一个链接,可以在前 3 个下方添加无限数量的文本框.
I have a link that adds an unlimited number of textboxes below the first 3.
我目前的变更声明:
$('input.#invent').change(function () {
适用于第一个文本框上的更改事件,但是具有相同信息的其他人在更改时不会触发它
works fine for the change event on the first textbox, but the others with the same information do not fire it when changed
当任何 3 个以上的文本框发生更改时,触发更改事件的最佳策略是什么??
What is the best strategy for getting the change event to fire when any of the 3+ textboxes change??
推荐答案
将 ID 为 #invent
的所有三个元素改为一个类(ID 的 必须是唯一的),否则它只适用于第一个元素,比如什么您的情况目前正在发生.
Change all three elements with the #invent
ID to a class instead (ID's must to be unique), or it's only going to work for the first element, like what's currently happening in your case.
然后,您可以定位所有具有 .invent
类的元素:
Then, you can target all of the elements that have the .invent
class:
$('input.invent').change(function () {
// Here, $(this) refers to the specific element of the .invent class which 'changed'
}):
详细了解 ID 和类选择器之间的区别这里一个>.
Read more about the difference between ID and Class selectors here.
这篇关于多个元素上的一个 jQuery 更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!