gpt4 book ai didi

css - Dart 语言 : how to get an image from another element?

转载 作者:行者123 更新时间:2023-11-28 09:48:41 25 4
gpt4 key购买 nike

我在一个 HTML 文件中有两个表格行:第一个是空的,另一个有背景图像。我想知道是否有任何方法可以获取该背景图像并在单击时将其转移到第一行。

(现在我在 CSS 代码中设置背景图片,但我认为我必须将它移到 HTML 中才能使其工作。或者可能不?)

感谢您的帮助!

最佳答案

index.html

<head>
<style>
div {
width: 50px;
height: 50px;
border: 1px solid red;
}
#id1 {
background-image: url('action-icons.png');
}
</style>
</head>
<body>
<div id='id1'>xxx</div>
<div id='id2'>yyy</div>
</body>

索引.dart

import 'dart:html';

main () {
querySelector('#id2').onClick.listen((e) {
var div1 = querySelector('#id1');
var div2 = querySelector('#id2');
div2.style.backgroundImage = div1.getComputedStyle().backgroundImage;
div1.style.backgroundImage = 'none';
});
}

关于css - Dart 语言 : how to get an image from another element?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24236276/

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