我不知道这是否可能,但下面我有一个简单的 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/