在IE7中无法使用jQuery选择未知属性

Can't select unknown attr's with jQuery in IE7

本文关键字:jQuery 选择 未知 属性 IE7      更新时间:2023-09-26

每次我尝试使用以下选择器选择div元素:

div#wl-add-position-steps div[data-step="1"] 

IE7无法更新返回的对象。

jQuery('div#wl-add-position-steps div[data-step="1"]').hide();
jQuery('div#wl-add-position-steps div[data-step="2"]').show();
HTML:

<div id="wl-add-position" style="display:none;">
    <div class="wl-description">
        <?php echo $this->translate('wlPositionAddDescription'); ?>
    </div>
    <div id="wl-add-position-steps" class="wl-steps cf">
        <ul>
            <li data-event-step="1" class="active"><span class="a-step"><?php echo $this->translate('stepX', 1); ?></span><?php echo $this->translate('wlPositionStep1'); ?></li>
            <li data-event-step="2"><span class="a-step"><?php echo $this->translate('stepX', 2); ?></span><?php echo $this->translate('wlPositionStep2'); ?></li>
            <li data-event-step="3"><span class="a-step"><?php echo $this->translate('stepX', 3); ?></span><?php echo $this->translate('wlPositionStep3'); ?>
            </li>
        </ul>
    </div>
    <div id="wl-add-position-steps">
        <div data-step="1">
            <input type="text" class="wl-search-full" id="wl-search-instrument" value="WKN/ISIN/Kürzel/Name" />
            <ul data-block="instruments" class="wl-result-list box twoline activites"></ul>
            <span data-block="nothing-found" style="display:none;">
                <br /><br />
                <img src="/common/img/watchlist-emptylist.png" align="center" class="search-no-warpper" />
            </span>
        </div>
        <div data-step="2" style="display:none;">
            <h3>
                <?php echo $this->translate('wlPostionAddStep3Title'); ?>
            </h3>
            <ul data-block="quoteSources" class="wl-result-list exchanges"></ul>
        </div>
        <div data-step="3" style="display:none;">
            <div class="modal-form-position">
                <div class="cf">
                    <label for="wl-instrument-name"><?php echo $this->translate('value'); ?></label>
                    <input type="text" name="wl-instrument-name" id="wl-instrument-name" readonly value="" />
                </div>
                <div class="cf">
                    <label for="wl-quotesource-name"><?php echo $this->translate('quotesource'); ?></label>
                    <input type="text" name="wl-quotesource-name" id="wl-quotesource-name" readonly value="" />
                </div>
                <div class="cf">
                    <label for="wl-instrument-value"><?php echo $this->translate('buyCourse'); ?></label>
                    <input type="text" name="wl-instrument-value" id="wl-instrument-value" value="" />
                </div>
                <div class="cf">
                    <label for="wl-position-date"><?php echo $this->translate('date'); ?></label>
                    <input type="text" name="wl-position-date" id="wl-position-date" value="<?php echo date('d.m.Y'); ?>" />
                </div>
                <div class="cf">
                    <label for="wl-position-comment"><?php echo $this->translate('comment'); ?></label>
                    <textarea id="wl-position-comment"></textarea>
                </div>
            </div>
        </div>
    </div>
</div>

这是一个已知的问题还是另一个问题?

好,这个问题很容易解决。IE7不能直接读取元素的children()。所以选择器不能得到元素div#wl-add-position-steps>div[data-step="1"]。使用select: [data-step="1"]。问题被纠正了!