简体   繁体   English

SVG 文本不会在移动浏览器上更新

[英]SVG Text doesn't update on mobile browser

I'm using the Ionic framework for my android app.我正在为我的 android 应用程序使用 Ionic 框架。

On my index I have a SVG Text along a path that will update with a new text on a button click.在我的索引上,我沿着路径有一个 SVG 文本,单击按钮时将更新为新文本。 On ionic server its OK and functional, but when I upload to the emulator the text simply doesn't update anymore.在离子服务器上它可以正常运行,但是当我上传到模拟器时,文本不再更新。

Here is my code:这是我的代码:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="svg" width="240px" height="63px" viewBox="-36.745 72.133 245.331 23.568">
    <defs>
        <path id="MyPath" d="M-36.745,89.659c0,0,17.786,8.625,51.934,0.671c0,0,97.811-22.88,152.395-14.463c0,0,20.615,5.33,40.871,15"/>
    </defs>
    <text>
        <textPath class="svgText" xlink:href="#MyPath"> 
            SVG TEXT THAT NEED UPDATE
        </textPath>
    </text>
</svg>
==========

<button id="cardApply" ng-click="updateText()">Update</button>

==========
updateText = function($title){
    var svgNewTitle = $title;

    $('.svgText').html(svgNewTitle);

};

Please just ignore the fact that I'm not using the Angular "goodies", I'm new to its "ways" and couldn't make it work properly.请忽略我没有使用 Angular 的“好东西”这一事实,我不熟悉它的“方式”,无法使其正常工作。 Jquery was the only way to make it work. Jquery 是使其工作的唯一方法。

The SVG text doesn't update on an android browser. SVG 文本不会在 android 浏览器上更新。

You want to write this as你想把它写成

$('.svgText')[0].textContent = svgNewTitle;

That's rather more portable than trying to use the .html() function.这比尝试使用 .html() 函数更便携。 The [0] converts the jQuery object to a raw DOM object. [0] 将 jQuery 对象转换为原始 DOM 对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM