gpt4 book ai didi

jquery - 将背景图像 Url 更改为输入字段的值

转载 作者:太空宇宙 更新时间:2023-11-04 05:23:07 24 4
gpt4 key购买 nike

我有一个输入元素、一个 span 和一个带有背景图像属性的 div。

<span>Go</span><input id="ImageUrl"/>

<div id="Image"></div>

我正在尝试创建一个脚本,如果用户在输入字段中粘贴/键入链接,然后单击 Go 按钮,div 的背景图像属性将更改为该 url。

最佳答案

在 中:

<script  type="text/javascript">
function show() {
$('#Image').css('background-image', 'url("' + $('#ImageUrl').val() + '")');
}
</script>

在 <正文> 中:

<span>Go</span><input id="ImageUrl"  /> <!-- the textbox can get the user input Url of Image-->
<div id="Image" style="width:200px; height:200px;"></div> <!-- the div which show Image -->
<input type="button" value="Go" onclick="show()" /> <!-- the GO button -->

如果你有问题请告诉我:)

关于jquery - 将背景图像 Url 更改为输入字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5987217/

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