1

I'm having an issue where I'm loading 3 DIV's from an AJAX source. The returning HTML looks a little like:

<div>
  <label for="firstName">First Name</label>
  <input id="firstName" name="firstName"....
</div>

So imagine this block duplicated 3 times in the same DOM. The problem is when I click on the label in the 3rd loaded DIV, its highlighting the text box in the 1st loaded DIV. So now what I have are 3 blocks of HTML where the ID's are clashing.

Does anyone know of any work around for this?

Thanks.

4

1 回答 1

3

具有相同 id 的多个元素不符合标准。因此,IE、Firefox 以一种方式运行,而 Chrome 以另一种方式运行。

一种方法是在从 AJAX 源加载 id 时对其进行修改。您可以提供一个占位符 id id="UNIQUE_id",然后使用where可能只是一个连续递增的数字.......html().replace(/UNIQUE_/g,something_unique));something_unique

于 2012-10-05T18:15:33.887 回答