2010-10-07 96 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