我有多個width="1" height="1"
的html。我想用border-image: none
來代替它們。正則表達式多個引號標記
我已經試過:
$printCanvas.html().replace(new RegExp("width=\"1\" height=\"1\"", 'g'), "border-image: none");
,似乎沒有奏效。有什麼建議麼?
-----更新------
對於那些誰問,爲什麼我不需要style
標籤:
其實,我是想處理它通過GoogleMap的生成的HTML在Edge
和IE10
。我正在使用庫,它將jQuery div轉換爲圖像,它在Edge
中工作,但不在IE10
中。即,html2canvas。我在這裏的輸出:issue with IE10, IE9
後仔細比較HTML,我看到的唯一區別是如下:
在IE10
,它有width="1" height="1"
標籤:
<div style="width: 66px; height: 26px; cursor: pointer;"><img width="1" height="1" style="margin: 0px; padding: 0px; border: 0px currentColor; left: 0px; top: 0px; width: 66px; height: 26px; position: absolute; -ms-user-select: none;" draggable="false" src="https://maps.gstatic.com/mapfiles/api-3/images/google4.png">
在Edge
:
<div style="width: 66px; height: 26px; cursor: pointer;"><img style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; left: 0px; top: 0px; width: 66px; height: 26px; position: absolute; -ms-user-select: none;" draggable="false" src="https://maps.gstatic.com/mapfiles/api-3/images/google4.png">
我在想使用正則表達式將所有width="1" height="1"
更改爲border-image:none
:
printCanvas.html().replace(new RegExp("width=\"1\"\\s+height=\"1\"", 'g'), "border-image: none");
,然後問html2canvas庫來處理它:
window.html2canvas(printCanvas, {
useCORS: true,
onrendered: function(canvas) {
const img = canvas.toDataURL("image/png");
base64Img = img;
base64Img = base64Img.replace('data:image/png;base64,', '');
resolve(base64Img);
}
});
,並沒有發生任何變化....仍然會在IE10空白。
下面在兩個瀏覽器對比所呈現的HTML屏幕:
你有沒有嘗試過寬度和高度屬性之間的空間? – MIE
你能提供一個jsfiddle鏈接嗎? – Thinker
用你當前的例子,你得到了printCanvas的html,然後替換了css樣式(width/height數據屬性),但是'replace'返回的值沒有被分配給$ printCanvas的html。你的代碼也不會有你想要的效果。 'border-image:none'需要插入到嵌入式樣式塊中,而不是插入到元素的數據屬性中。 –