2010-10-07 63 views
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'); 
     } 
    }); 
}); 

回答

0

你比较title到其中的href e元素?我相信在IE中它使用绝对的url而不是相对的,所以你可能想在假设某些东西能够工作之前仔细检查href的值。

您可以使用[href*=,而不是href=

不要假设,经常检查。在attr('href')上发出警报,并确保它们匹配。

+0

谢谢meder。这一周的黑客攻击已经很辛苦,但我确实有一个工作解决方案,我会在休息时发布信息,以便其他人可以看到解决方案 – shecky 2010-10-07 17:54:24