如何在表单中找到重复的ID? [英] How to find duplicate id's in a form?
本文介绍了如何在表单中找到重复的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个包含大约800个字段的表单。在不知不觉中,我为表格中的几个字段提供了相同的id。如何追踪它们?
http://validator.w3.org/ 将是方便的解决方案。但是使用 jquery ,你可以这样做: // //查看您的控制台是否有重复的id
$ b $('[id]')。each(function(){
var id = $('[id =''+ this.id +'''');
if(id.length> 1&& id [0] == this){
console.log('Duplicate id'+ this.id);
alert('duplicate found') ;
}
});
希望这有助于您。
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?
解决方案
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.
这篇关于如何在表单中找到重复的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文