-1

我正在尝试从 style 更改 url(herf) 。核实

<iframe src="https://www.website.com/............" heght="100%" width="100%" >

#document

<!DOCTYPE html>

<html> 
<head></head>
<body>

<a class="class"  href="https://www.website.com/-----"  style="background: url(&quot;https://www.website.com/abc.png&quot;) center center / 100% no-repeat; width: 110px; height: 26px;"></a>

</body>
</html>

<iframe>

我想用 javascript 更改图片 url

: style="background: url(&quot;https://www.website.com/abc.png&quot;)

使用另一个网址。

像那样

: style="background: url(&quot;https://www.website.com/xyz.png&quot;)

图像 xyz.png 中的重要更改。

4

4 回答 4

0
document.getElementsByTagName('iframe')[0].src = "https://www.website.com/xyz.png";

获取 iframe src 并更新 src。希望对你有帮助

于 2017-09-15T12:38:48.697 回答
0

要从 Javascript 更改元素的样式,您可以这样做:

<!-- Suppose you have this <a> element -->
<a id="my-link" style="background: ...; ...">...</a>

<!-- This is the code -->
<script>
    document.getElementById("my-link").style.background = "url('https://www.website.com/abc.png') center center / 100% no-repeat";
</script>

这是你想要的吗?

于 2017-09-15T12:43:44.547 回答
0
<script>
document.getElementById("iframe").setAttribute('style',' background-image: url(https://www.website.com/xyz.png);background-repeat: no-repeat;    background-size: 100% 100%;');
</script>

尝试这个

于 2017-09-15T12:54:54.387 回答
0

我找到了,试试看

<!DOCTYPE html>
<html>
<body>

<ul>
  <li>Coffee</li>
  <li>Tea</li>
</ul>

<p>Click the button to change the text of the first list item (index 0).</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var list = document.getElementsByTagName("UL")[0];
    list.getElementsByTagName("LI")[0].innerHTML = "Milk";
}
</script>

</body>
</html>

于 2017-09-20T09:33:26.457 回答