How to find duplicate id's in a form?

后端 未结 6 2615
无人及你
无人及你 2021-02-20 13:16

I\'ve created a form with about 800 fields in it. Unknowingly I\'ve given same id for few fields in the form. How to trace them?

6条回答
  •  青春惊慌失措
    2021-02-20 13:38

    The http://validator.w3.org/ will be the handy solution. But using jquery you can do something like this:

    //See your console for duplicate ids
    
    $('[id]').each(function(){
      var id = $('[id="'+this.id+'"]');
      if(id.length>1 && id[0]==this) {
        console.log('Duplicate id '+this.id);
        alert('duplicate found');
      }
    });
    

    Hope this helps.

提交回复
热议问题