問題描述
我有 3 個文本框,它們都具有相同的 id,我通過將其放入控制器數(shù)組中處理到 ASP 中
I have 3 textboxes, all with the same id's that I process into ASP by bringing it into a controller array
我有一個鏈接,可以在前 3 個下方添加無限數(shù)量的文本框.
I have a link that adds an unlimited number of textboxes below the first 3.
我目前的變更聲明:
$('input.#invent').change(function () {
適用于第一個文本框上的更改事件,但是具有相同信息的其他人在更改時不會觸發(fā)它
works fine for the change event on the first textbox, but the others with the same information do not fire it when changed
當任何 3 個以上的文本框發(fā)生更改時,觸發(fā)更改事件的最佳策略是什么??
What is the best strategy for getting the change event to fire when any of the 3+ textboxes change??
推薦答案
將 ID 為 #invent
的所有三個元素改為一個類(ID 的 必須是唯一的),否則它只適用于第一個元素,比如什么您的情況目前正在發(fā)生.
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 和類選擇器之間的區(qū)別這里一個>.
Read more about the difference between ID and Class selectors here.
這篇關于多個元素上的一個 jQuery 更改事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!