首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用Javascript更改SVG路径的属性值

无法使用Javascript更改SVG路径的属性值
EN

Stack Overflow用户
提问于 2019-08-29 17:01:44
回答 1查看 161关注 0票数 0

我使用snap.svg创建了一个SVG路径,你可以在下面看到它的代码。现在,我正在尝试更改属性的值,例如strokeWidth。为此,我创建了一个文本输入框和一个按钮,该按钮运行一个函数,该函数应为strokeWidth填充一个新值。但它不起作用。我做错了什么?有没有可能我甚至不能改变这个值?我还发布了输入框和按钮+我的函数的代码,用于在下面更改笔划宽度

我尝试了很多不同的函数和脚本,但似乎都不起作用。有时我会收到一条错误消息,有时却不会。当我收到错误消息时,它总是说函数未定义或L_PUF_WAR未定义。

代码语言:javascript
复制
var L_PUF_WAR = s.path("m 937.88689,516.10127 v -51.8831 H 573.37482 V 340.49692 H 391.11879 V 276.6408").attr({
                        fill: "none",
                        stroke: "#bada55",
                        strokeWidth: 15,
                        strokeDasharray: "30, 30 ,30"
                    });
                    A_PUF.append(L_PUF_WAR);```       
代码语言:javascript
复制
    <script>
        function hallo(){
            var number = document.getElementById("number").value;
            if(number > 0){
                L_PUF_WAR.strokeWidth = number;
            }
        }
    </script>
        <input type="text" id="number" name="number"/><br/>  
        <input type="button" value="breite" onclick="hallo()"/> 
代码语言:javascript
复制
I am expecting to put in a value for the strokewidth into the Input Box for example 20 and then the strokeWidth should change to that value..
EN

回答 1

Stack Overflow用户

发布于 2019-08-29 17:17:14

尝试使用.setAttribute()

代码语言:javascript
复制
L_PUF_WAR.setAttribute("strokeWidth", number);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57706654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档