0
啊,如果還有一個IE瀏覽器,它真的會結束嗎?IE7無法根據它的href屬性刪除一個元素
感謝Stack Overflowers的無價幫助,我的jQuery可以在FF,Safari,Chrome & Oprah中完美工作。當然,它不能在IE7中,這顯然是有困難的href屬性,例如:
$('li a[href="' + title + '"]').parent().remove();
有人可以闡明一個替代語法IE7就會明白,從列表中刪除未覈對的項目一些啓示?提前謝謝了!
這裏的作品:
<div class="product-module">
<div class="product-pic">
<div class="checkbox-wrapper">
<label for="compare1">
<input type="checkbox" class="checkbox" name="compare" id="compare1" />
Compare
</label>
</div>
</div>
<div class="product-info">
<p><a href="#" title="#"><span class="product-name">Product Name here</span></a></p>
</div>
<div class="compare">
<ul>
</ul>
<p class="compare-button"><button type="submit">Compare</button></p>
<p class="clear-selections"><a class="button" id="clear-selections" href="#">Clear Selections</a></p>
<script type="text/javascript">
// clear all checkboxes on load
$(function(){
$('input[type="checkbox"]').attr('checked', false);
});
$(function(){
$('.column-main input[type="checkbox"]').click(function() {
var title = $(this).closest('.product-module').find('.product-name').html();
// if user checks the checkbox, add the item to the ul
if ($(this).attr('checked')) {
var html = '<li><a href="'+title+'">' + title + '</a></li>';
$('.compare ul').append(html);
// un-checking the checkbox removes the corresponding item from the ul
} else {
// $('.compare li a').attr('href', title).parent().remove();
$('li a[href="' + title + '"]').parent().remove(); // works in real browsers; fails in IE7
}
})
});
$(function(){
$('.clear-selections').click(function(){
$('.compare ul').empty();
$('input[type="checkbox"]').attr('checked', false);
})
});
$(function(){
$('.compare button').click(function(){
minRequests = 2;
maxRequests = 3;
requested = $('.compare ul li').size(); // go figure: why not .length()?
if(requested < 2) {
alert ('Compare ' + requested + ' products?');
} else if((requested >= 2) && (requested <= 5)) {
alert ('There are ' + requested + ' products to compare');
} else {
alert (requested + ' is too many');
}
});
});
謝謝meder。這一週的黑客攻擊已經很辛苦,但我確實有一個工作解決方案,我會在休息時發佈信息,以便其他人可以看到解決方案 – shecky 2010-10-07 17:54:24