2 shenpeihu ShenPeiHu 于 2014.07.02 09:24 提问

<canvas> 兼容IE8 , 文本(txt)无法在IE中显示出来

ctx.fillText(txt,x+3, y+15);

加上这两个方法 文本(txt)还是无法在IE中显示出来,求助sos,谢谢

contextPrototype.measureText = function(textToDraw) {

var hiddenSpan = document.createElement('span');

hiddenSpan.style.font = this.font;

hiddenSpan.innerHTML = textToDraw;

var bodyNode = document.getElementsByTagName("body")[0];

bodyNode.appendChild(hiddenSpan);

var width = hiddenSpan.offsetWidth;

bodyNode.removeChild(hiddenSpan);

this.strokeStyle = '#000';

this.fillStyle = '#000';

this.font = '12px sans-serif';

return {"width" : width + 1};

}

contextPrototype.fillText=function(textToDraw, x, y) {

var vmlStr = [];

var textHeightStr = this.font.split("px")[0].replace(/(^\s+)|(\s+$)/g, "");

var textHeight = /^\d+$/.test(textHeightStr) ? parseInt(textHeightStr) : 0;

vmlStr.push(' ' >' + textToDraw,

' ',

'');

this.element_.insertAdjacentHTML('BeforeEnd', vmlStr.join(''));   

};

1个回答

qq_35228841
qq_35228841   2016.09.28 13:46

我也是这样,你搞定了么,怎么弄的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!