Svg文本在safari和IE中不起作用,但它对chrome和firefox工作正常

时间:2015-06-30 16:36:05

标签: text setattribute

 text[i + 1] = document.createElementNS("http://www.w3.org/2000/svg", "text");
            text[i + 1].setAttribute('x', legendX[i + 1] - 15);
            text[i + 1].setAttribute('y', legendY[i + 1] + 30);
            text[i + 1].setAttribute('style', "fill;red");
            text[i + 1].id = "text" + (i + 1);
            svgmain.appendChild(text[i + 1]);
            document.getElementById(text[i + 1].id).innerHTML = yearAllTimelineDates[i + 1][1].toString().substring(0, 4);

//所以我使用innerHTML属性来设置文本值

1 个答案:

答案 0 :(得分:0)

使用此,

document.getElementById(text[i + 1].id).textContent= yearAllTimelineDates[i + 1][1].toString().substring(0, 4);