Is there any proper way to reuse Id's?

后端 未结 3 1364
广开言路
广开言路 2021-01-28 07:50

I have a \"create\" form inside a bootstrap\'s modal. All my Javascript related with that form uses id\'s and not class

3条回答
  •  灰色年华
    2021-01-28 08:36

    If you insist on using two forms on one 'page' and share ids between them, you have few options to make it work and be relatively 'clean' about it. Not knowing your technology stack, I can't give a completely relevant answer. However you can do something similar to the below:

    HTML

    JAVASCRIPT

     $("#myFormDiv").load(urlToForm);
    

    You would naturally need your forms to be in separate html files for this to work as there is no way you can reliably use ids on multiple elements in one html file.

提交回复
热议问题