"此页面上的另一个对象已使用ID' XXXXXXX'

时间:2016-01-22 17:50:46

标签: c# jquery asp.net jquery-multiselect

与:无关: Another object on this page already uses ID 'XXXXXXX'

我的页面上有一个jQuery Multiselect Listbox控件:

jQuery(document).ready(function () {
    jQuery(function () {
        jQuery("#UCStyle1 select").multiselect({
                header: true,
                height: 175,
                minWidth: 240,
                size: 3,
                classes: '',
                checkAllText: 'Check all',
                uncheckAllText: 'Uncheck all',
                noneSelectedText: '0 Selected',
                selectedText: '# selected',
                selectedList: 0,
                show: null,
                hide: null,
                autoOpen: false,
                multiple: true,
                position: {},
                appendTo: "body"
        });
});

它在div标签中引用了很多次,如下所示:

<tr>
    <td>
        Looking for:
    </td>
    <td colspan="3">
        <div id="UCStyle1">
            <asp:ListBox ID="MatchGender" SelectionMode="Multiple" runat="server">
            </asp:ListBox>
        </div>
    </td>
</tr>
<tr>
    <td>
        State:
    </td>
    <td colspan="3">
        <div id="UCStyle1">
            <asp:ListBox ID="sState" SelectionMode="Multiple" runat="server">
            </asp:ListBox>
        </div>
    </td>
</tr>

因此,他们需要引用jQuery,但它们是不同的控件。

我收到了警告:

  

此页面上的另一个对象已使用ID&#39; ucstyle1&#39;

多次。

知道如何清理它以便我不会收到警告吗?我认为这会让网页在IE浏览器上显得格格不入,但Firefox似乎并不关心它。

1 个答案:

答案 0 :(得分:2)

您有两个div代码与id UCStyle1相同但由于id是唯一的,因此您无法在页面中使用重复的代码。如果您想重复,可以使用class代替id

<div class="UCStyle1">

<div class="UCStyle1">

jQuery(".UCStyle1 select").multiselect({