Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript <;元素>;。刚毛属性(';http://www.w3.org/1999/xlink',&&x27;xlink:href&&x27;&&&x27;<;参考>;&x27;);不在Firefox中工作_Javascript_Html_Svg - Fatal编程技术网

Javascript <;元素>;。刚毛属性(';http://www.w3.org/1999/xlink',&&x27;xlink:href&&x27;&&&x27;<;参考>;&x27;);不在Firefox中工作

Javascript <;元素>;。刚毛属性(';http://www.w3.org/1999/xlink',&&x27;xlink:href&&x27;&&&x27;<;参考>;&x27;);不在Firefox中工作,javascript,html,svg,Javascript,Html,Svg,我想通过使用javascript更改“use”标记的href来更改我在html页面中使用的svg代码。该代码在Chrome中运行良好,但在Firefox中效果不佳 感谢您的帮助:) 编辑我的代码 // javascript function OnHover(x) { switch (x) { case 1: document.getElementById("icon2svg").setAttributeNS('http://ww

我想通过使用javascript更改“use”标记的href来更改我在html页面中使用的svg代码。该代码在Chrome中运行良好,但在Firefox中效果不佳

感谢您的帮助:)

编辑我的代码

// javascript


function OnHover(x)
{
    switch (x)
    {
            case 1:
            document.getElementById("icon2svg").setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#SVGicon-2-grad');
            break;
        case 2:
            document.getElementById("icon2svg").setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#SVGicon-2');
            break;
        case 3:...
    }
}


<!-- HTML -->



<div id="vi2" class="vertical-inner-inactive">
    <svg> <use id="icon2svg" xlink:href="#SVGicon-2"></use></svg>
    <p id="icon2text">Text</p>
</div>

<svg version="1.1" id="SVGicon-2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 350 350">
    <path fill="#fff" d="M173.332,277.78v0.021c0,0-0.009-0.004-0.022-0.011c-0.014,0.007-0.022,0.011-0.022,0.011v-0.021
    c-2.244-1.036-97.775-45.949-89.042-180.789c0,0,39.924-3.001,89.042-27V69.97c0.007,0.003,0.015,0.007,0.022,0.011
    c0.008-0.004,0.014-0.008,0.022-0.011v0.021c49.117,23.999,89.041,27,89.041,27C271.107,231.831,175.577,276.744,173.332,277.78z
     M173.443,307.058c-2.9-1.313-123.891-58.404-111.484-229.797c2.538-0.191,50.776-3.814,113.438-34.318
    c62.256,30.503,110.439,34.127,112.975,34.318C298.166,248.653,176.305,305.744,173.443,307.058z M271.104,89.453
    c0,0-43.838-3.295-97.771-29.646v-0.024c-0.007,0.004-0.016,0.007-0.024,0.012c-0.008-0.004-0.017-0.008-0.024-0.012v0.024
    c-53.933,26.351-97.771,29.646-97.771,29.646c-9.59,148.058,95.307,197.376,97.771,198.514v0.022c0,0,0.009-0.006,0.024-0.011
    c0.015,0.005,0.024,0.011,0.024,0.011v-0.022C175.798,286.829,280.695,237.511,271.104,89.453z"/>
</svg>

<svg version="1.1" id="SVGicon-2-grad" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 350 350">
<path fill="url(#PINK-RED_topdown)" d="M173.332,277.78v0.021c0,0-0.009-0.004-0.022-0.011c-0.014,0.007-0.022,0.011-0.022,0.011v-0.021
    c-2.244-1.036-97.775-45.949-89.042-180.789c0,0,39.924-3.001,89.042-27V69.97c0.007,0.003,0.015,0.007,0.022,0.011
    c0.008-0.004,0.014-0.008,0.022-0.011v0.021c49.117,23.999,89.041,27,89.041,27C271.107,231.831,175.577,276.744,173.332,277.78z
     M173.443,307.058c-2.9-1.313-123.891-58.404-111.484-229.797c2.538-0.191,50.776-3.814,113.438-34.318
    c62.256,30.503,110.439,34.127,112.975,34.318C298.166,248.653,176.305,305.744,173.443,307.058z M271.104,89.453
    c0,0-43.838-3.295-97.771-29.646v-0.024c-0.007,0.004-0.016,0.007-0.024,0.012c-0.008-0.004-0.017-0.008-0.024-0.012v0.024
    c-53.933,26.351-97.771,29.646-97.771,29.646c-9.59,148.058,95.307,197.376,97.771,198.514v0.022c0,0,0.009-0.006,0.024-0.011
    c0.015,0.005,0.024,0.011,0.024,0.011v-0.022C175.798,286.829,280.695,237.511,271.104,89.453z"/>
</svg>
//javascript
函数OnHover(x)
{
开关(x)
{
案例1:
document.getElementById(“ICON2SSVG”).setAttributeNS('http://www.w3.org/1999/xlink'、'xlink:href'、'SVGicon-2-grad');
打破
案例2:
document.getElementById(“ICON2SSVG”).setAttributeNS('http://www.w3.org/1999/xlink'、'xlink:href'、'SVGicon-2');
打破
案例3:。。。
}
}
文本


只需使用href而不是xlink:href

x=1
函数go()
{
OnHover(x);
x=3-x;
}
函数OnHover(x)
{
开关(x)
{
案例1:
document.getElementById(“ICON2SSVG”).setAttributeNS('http://www.w3.org/1999/xlink“,”href“,”SVGicon-2-grad“;
打破
案例2:
document.getElementById(“ICON2SSVG”).setAttributeNS('http://www.w3.org/1999/xlink“,”href“,”SVGicon-2“;
打破
}
}

文本


实际的javascript比你自己编造的伪代码要好。你能解释一下代码吗。我不是javascript方面的专家。Firefox中有很多回归测试和其他测试,它们在每次构建时都能正常工作。因此,您的代码中可能存在错误,或者您的问题与您正在描述的问题不同,但在没有看到您的代码的情况下,我无法判断它是什么。
请您解释一下该代码。我不是javascript方面的专业人士
——这是无效的javascript,因此我无法解释您的错误code@AshwinThomas请在你的问题中添加一个。