Jquery IE7未能根据元素的href属性删除元素
啊,如果还有一个IE,它真的结束了吗 多亏了Stack Overflowers的宝贵帮助,我的jQuery在FF、Safari、Chrome和Oprah中工作得非常好。当然,它在IE7中失败,IE7显然有问题的href属性,例如:Jquery IE7未能根据元素的href属性删除元素,jquery,internet-explorer-7,internet-explorer-6,Jquery,Internet Explorer 7,Internet Explorer 6,啊,如果还有一个IE,它真的结束了吗 多亏了Stack Overflowers的宝贵帮助,我的jQuery在FF、Safari、Chrome和Oprah中工作得非常好。当然,它在IE7中失败,IE7显然有问题的href属性,例如: $('li a[href="' + title + '"]').parent().remove(); 有人能解释一下IE7可以理解的从列表中删除未选中项的另一种语法吗?非常感谢 作品如下: <div class="product-module"> <
$('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>
您是否将标题与元素的href进行了比较?我相信IE使用的是绝对url,而不是相对url,因此在假设某项功能正常工作之前,您可能需要仔细检查href值
您可以使用[href*=而不是href=
永远不要假设,总是检查。在attr'href'上发出警报,并确保它们匹配。谢谢meder。这一周的黑客攻击让人筋疲力尽,但我确实有一个可行的解决方案,我会在休息时尝试发布,以便其他人可以看到解决方案
<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');
}
});
});