2013-04-30 173 views
0

我將我的精選圖像包裹在一個圖元素中。但是,IE8不能正確識別圖形元素,並形成我的圖像。所以,我試圖用jQuery來檢測IE8,並用一個簡單的div元素替換figure元素。jQuery用另一個元素標記替換匹配的元素

這裏是我測試的jQuery:

jQuery('.entry figure.figureFeatured').replaceWith(
    jQuery('<div/>').html(
     jQuery('.entry figure.figureFeatured').html() 
     ) 
    ); 

它(根據Chrome的檢查員)

回答

0

下面的代碼使用複製工作正常,除了原有的數字元素的屬性不再附着在更換div元素屬性太...

jQuery('.entry figure.figureFeatured').replaceWith(
    var $div=jQuery('<div/>'); 
    $div.html(jQuery('.entry figure.figureFeatured').html()) 
    $div.attr(jQuery('.entry figure.figureFeatured').getAttributes()); 
    ); 

您需要的getAttributes功能就像添加到下面的Jquery

(function($) { 
    $.fn.getAttributes = function() { 
     var attributes = {}; 

     if(this.length) { 
      $.each(this[0].attributes, function(index, attr) { 
       attributes[ attr.name ] = attr.value; 
      }); 
     } 

     return attributes; 
    }; 
})(jQuery); 
相關問題