在使用jquery中的load函數動態加載html頁面時,html頁面中帶有background-image 元素。在IE瀏覽器中不能正確顯示背景圖片。好比: css
<html> <head> <style type='text/css'> div.role_underline{ height: 3px; width: 200px; background-image: url('images/role_underline.png'); background-repeat: repeat-x; background-position:center; } </style> </head> <body> <div class='role_underline'></div> </body> </html>
當咱們在IE瀏覽器中,使用jquery 的load函數加載上面代碼時並不能看到背景圖片,可是firebox瀏覽器顯示是正常的。 html
如何解決:方法一:不在css中定義背景圖片,在元素的style中設置。<div class='role_underline' style="background-image: url('images/role_underline.png');"></div> jquery
方法二:在load 的回調函數中從新設置背景圖片。$("div.role_under_line").css("background-image:","url('images/role_underline.png')"); 瀏覽器
注意:當咱們使用jquery 動態添加帶有背景圖片的元素時,也須要使用這方法。 函數