gpt4 book ai didi

javascript - 如果 `if` 语句匹配,如何将图像附加到表中?

转载 作者:行者123 更新时间:2023-11-27 22:41:19 25 4
gpt4 key购买 nike

我不知道是否可行,但下面我有一个简单的 html 表格:

<table id="plus" align="center">
<tr>
<th>
</th>
</tr>
</table>

如果if语句匹配,那么是否可以将图像附加到 <th> 中上面的标签?如果语句不匹配,那么我可以将图像链接附加到 <th> 中吗?标签?

下面是if语句,实际上是 jQuery,其中包含一些 php 来尝试查找“textQuestion”:

if (qnum == <?php echo (int)$_SESSION['textQuestion']; ?>) {
<img src="Images/plussigndisabled.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" name="plusbuttonrow"/>
} else {
<a onclick="return plusbutton();">
<img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" name="plusbuttonrow"/>
</a>
}

最佳答案

既然你说你正在使用 jQuery,你就可以这样做

....
var enabledImage = "plussign.jpg";
var disabledImage = "plussigndisabled.jpg";
var selectedImage;
var imageHtml;

if(...) {
selectedImage = enabledImage;
} else {
selectedImage = disabledImage;
}

imageHtml = getImageHtml(selectedImage);
$('#ElementID').append($(imageHtml));
....

function getImageHtml(imageFileName) {
return '<img src="Images/' + imageFileName + '" width="30" height="30" alt="Look Up Previous Question" class="plusimage" name="plusbuttonrow"/>';
}

关于javascript - 如果 `if` 语句匹配,如何将图像附加到表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10770385/

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