gpt4 book ai didi

javascript - 根据 SELECT 更改图像 SRC

转载 作者:行者123 更新时间:2023-11-30 18:58:10 24 4
gpt4 key购买 nike

我有一个选择标签,每次加载页面时都会填充一个文件列表。我希望每次在选择输入中单击一个图像时,图像都会更改为所选文件。这就是我现在拥有的,但无法正常工作。然而,当它被点击时,图像和文本是可见的/隐藏的。任何帮助将不胜感激。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Table Edit The Shakespeare Studio </title>
<link rel="stylesheet" type="text/css" href="../styles.css" />
</head>
<body>
<script language="javascript" type="text/javascript">
function edit_image1()
{
if (document.getElementById('select1').value == "0") {
document.preview1.style.visibility = "hidden";
document.getElementById('random1').style.visibility = "visible";
} else {
var selected = document.getElementById('select1').options[document.getElementById('select1').selectedIndex].value;
document.preview1.style.visibility = "visible";
document.preview1.src = "../resources/uploads/"+selected;
document.getElementById('random1').style.visibility = "hidden";
}
}
</script>
<div id="everything">
<form action='tableEdit.php' method='GET'>
<table border='1' id='cal'>
<tr id='top'><td> Page Name </td><td> Image to Use </td><td> Preview </td></tr>
<tr>
<td> about </td>
<td>
<select name='aboutImage' id='select1' onchange='edit_image1()';>
<option value='0' selected> RANDOM IMAGE</option>
<option value='IMG_6027.JPG'>IMG_6027.JPG</option>
<option value='IMG_6032.JPG'>IMG_6032.JPG</option>
<option value='kissme-1.jpg'>kissme-1.jpg</option>
</select>
</td>
<td>
<img name='preview1' src='../resources/uploads/0'></img>
<h3 id='random1'> Random </h3>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

最佳答案

当我做类似的事情时,我创建了一个新的 Image脚本中的对象。您应该能够通过构建一个“<IMG>”元素并设置innerHTML来简单地做到这一点。 parent 的属性(property)。

编辑:像这样:

<html>
<head>
<title>Image Replacement Example</title>
</head>
<body>
<div id="imageHolder">
<img src="http://stackoverflow.com/content/img/so/logo.png">
</div>
<br>
<button onClick="javascript:newImage();return false;">Click Me</button>

<script type="text/javascript">
function newImage()
{
var holder = document.getElementById("imageHolder");
holder.innerHTML = "<img src='http://serverfault.com/content/img/sf/logo.png'>"
}
</script>

关于javascript - 根据 SELECT 更改图像 SRC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1111471/

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