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 更改事件


- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01