2

不相关: 此页面上的另一个对象已使用 ID 'XXXXXXX'

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

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 'ucstyle1'

多次。

知道如何清理它以免收到警告吗?我认为它导致页面在 IE 上看起来完全不稳定,但 Firefox 似乎并不关心它。

4

1 回答 1

2

您有两个div具有相同id( UCStyle1) 的标签,但由于id是唯一的,因此您不能在页面中使用重复的标签。如果你想重复它,你可以使用class而不是。id

<div class="UCStyle1">

<div class="UCStyle1">

和:

jQuery(".UCStyle1 select").multiselect({
于 2016-01-22T17:54:55.647 回答