gpt4 book ai didi

javascript - svg-insertAdjacentHTML 不适用于 firefox 35 及以下版本?

转载 作者:搜寻专家 更新时间:2023-10-31 22:57:41 24 4
gpt4 key购买 nike

我正在尝试使用 svg 绘制一条线。所以我使用了 insertAdjacentHTML。但这适用于 chrome 但不适用于 firefox。

我的html代码如下

<div style="height:330px; width:1100px; background:#313131; margin:0 auto; ">
<svg id='svg_main' height="330" width="1100"></svg>
</div>

我的javascript如下

var svgid = document.getElementById('svg_main');
var str_lne = 60;
var data = '<path id="lineAB" d="M 50 '+str_lne+' L 1050 '+(str_lne)+'" transform="translate(0.5,0.5)" stroke="#707073" fill="none" storke-width="1px" opacity="1" ></path>';
svgid.insertAdjacentHTML('beforeend',data);

它不在 firefox(35 以下)上的本地主机上运行。

例如,

我打开 firefox 并输入 url (localhost/svgtest.html) 现在 svg 行没有显示。但是,我通过 ctrl+s 保存页面并通过 firefox 打开它显示了该行。

run on the firefox by using localhost simply open the file on firefox请帮助我解决这个问题并阐明问题的原因。

最佳答案

您的代码在 Firefox 中运行良好。除了您有错字 (storke-width)。

var svgid = document.getElementById('svg_main');
var str_lne = 60;
var data = '<path id="lineAB" d="M 50 '+str_lne+' L 1050 '+(str_lne)+'" transform="translate(0.5,0.5)" stroke="#707073" fill="none" stroke-width="1px" opacity="1" ></path>';
svgid.insertAdjacentHTML('beforeend',data);
<div style="height:330px; width:1100px; background:#313131; margin:0 auto; ">
<svg id='svg_main' height="330" width="1100"></svg>
</div>

关于javascript - svg-insertAdjacentHTML 不适用于 firefox 35 及以下版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38305818/

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