一个jQuery更改多个元素的事件 [英] One jQuery Change Event on Multiple Elements
问题描述
我有3个文本框,全部使用相同的id,通过将它们放入控制器数组中进行处理。
我有一个链接,可以添加无限数量的
我目前的变更声明:
$('input。#invent')。change(function(){
第一个文本框中的事件
,但具有相同信息的其他人在更改时不会触发它
获取更改事件触发的最佳策略是什么当3个文本框中的任何一个发生变化时 使用更改所有三个元素> #invent
ID改为类(ID的 必须是独特的 ),或者它只适用于第一个元素,比如你的情况正在发生。
.invent
类的元素: $ ('input.invent')。change(function(){
//这里,$(this)引用.invent类的特定元素,它'改变'
}):
详细了解ID和类选择器之间的区别 here 。
I have 3 textboxes, all with the same id's that I process into ASP by bringing it into a controller array
I have a link that adds an unlimited number of textboxes below the first 3.
My current change statement:
$('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
What is the best strategy for getting the change event to fire when any of the 3+ textboxes change??
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.
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'
}):
Read more about the difference between ID and Class selectors here.
这篇关于一个jQuery更改多个元素的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!