Html duplicated ID

后端 未结 8 1774
渐次进展
渐次进展 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:34

    I do understand that "Id" should be unique, however, with the outest with different "id", can it help in solving the problem?

    No. Having non-unique element ids will not work. Not consistently, in any case (different browsers and frameworks may handle this case differently).

    Any experts out there can give me some good advises?

    Prefer using class over using id, particularly for any component which may be reused multiple times on a page.

    Set ids against the containing elements themselves instead of the internal component elements, and revise your jQuery selectors accordingly. Or alternately implement your component such that it takes a 'namespace' parameter/attribute when used, and prefix each classname with the namespace inside of your component (this approach works particularly well when creating custom JSP tags).

    0 讨论(0)
  • 2020-12-02 00:37

    You can't have the same id multiple times. Use class instead.

    0 讨论(0)
提交回复
热议问题