gpt4 book ai didi

javascript - 使用 JS 将属性应用于 SVG 提示 'this.textBox.style is undefined' 。为什么?

转载 作者:可可西里 更新时间:2023-11-01 12:53:55 27 4
gpt4 key购买 nike

我使用以下代码绘制一个 SVG 文本框,然后将其文本 anchor 属性更改为“左”,因为它默认居中,这很糟糕。

文本生成正确,但是当我添加第二行时,我在错误控制台中收到错误“this.textBox.style is undefined”。

这是我的代码:

    RenderTextBox:function()
{
// Render Text
this.textBox = paper.text(this.x, this.y, this.htmlText);
this.textBox.style.textAnchor="left";
}

有什么想法吗?

最佳答案

我觉得你想做的是

this.textBox.setAttribute('text-anchor', 'start');

(或者,因为看起来您正在使用 Raphael)

this.textBox.attr( 'text-anchor', 'start' );

text-anchor 的有效值为startmiddleendinherit

关于javascript - 使用 JS 将属性应用于 SVG 提示 'this.textBox.style is undefined' 。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3015943/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com