![](/img/trans.png)
[英]website slider is not working on Google Chrome and Mozilla firefox
[英]Javascript code working in Mozilla Firefox but not in Google Chrome
我的JavaScript代碼遇到了一個小問題。 實際上,它可以在Firefox中運行,但不能在Chrome中運行,您是否知道為什么我會遇到此問題?
這是我的代碼:
$('a').each(function(){
if($(this).css('background-image')=='url("linktothepng.png")'){
$(this).parent().remove();
}
});
謝謝您的幫助,祝您有美好的一天;)
chrome將以url(linktothepng.png)
獲取它(不帶引號)
瀏覽器以自己的方式解析css並設置其格式,建議不要在這些屬性上進行文本匹配,僅使用具有該背景的類並與hasClass()
進行檢查以防止不一致
css('background-image')
返回的值可以通過不同的瀏覽器以不同的方式進行歸一化。 只要它們是等效的CSS,它們都有效。
您可以測試css('background-image').indexOf('linktothepng.png') != -1
是否可行, linktothepng.png
是沒有使用另一張以linktothepng.png
作為其名稱一部分的圖像(將需要更復雜的測試)。
如果可能的話,最好只通過設置類來設置背景圖像。
if($(this).hasClass('the-class-you-use')
刪除測試並將選擇器更改為$('a.the-class-you-use')
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.