One jQuery Change Event on Multiple Elements(多个元素上的一个 jQuery 更改事件)
问题描述
我有 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 更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:多个元素上的一个 jQuery 更改事件


基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01