Html duplicated ID

后端 未结 8 1802
渐次进展
渐次进展 2020-12-01 23:41

My control is built dynamically accordingly to user input, there are n textboxes whose IDs are dynamic too.

However, I did not foresee that this HTML w

8条回答
  •  没有蜡笔的小新
    2020-12-02 00:10

    You absolutely should not have duplicate IDs. It may work*, but it is semantically incorrect and you should not do it

    You should restructure your jQuery, however much that may stink. The best option would be to use a class, perhaps using the specific id of the parent to specify which one you want

    Another less attractive but viable way would be to add a number or something to the end of the ID to make it unique then use jQuery to detect any elements with a specific part of an ID

    * - As Arun describes jQuery will accept the selector, but it is NOT favorable because it is incorrect

提交回复
热议问题