gpt4 book ai didi

javascript - 使用逗号分隔符将文本替换为图像标签

转载 作者:行者123 更新时间:2023-12-03 08:13:46 35 4
gpt4 key购买 nike

代码正在使用jquery,我正在尝试将文本更改为带有逗号分隔符的图像标签,因此每个单词我都需要图像标签。在这种情况下,当图像被替换时,30 度水洗就消失了。

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(document).ready(function() {
$('.pa_wash .attribute-value:contains("iron")').html('<img src="edit.png"/>');
});
</script>
</head>
<body>
<li class="pa_wash">
<span class="attribute-label">Wash : </span>
<span class="attribute-value">30 Degree Wash, iron</span>
</li>
</body>
</html>

最佳答案

$(document).ready(function () {
$('.pa_wash .attribute-value:contains("iron")').html(function () {
return this.innerHTML
.replace("iron", '<img src="edit_0.png"/>')
.replace("30 Degree Wash", '<img src="edit_1.png"/>');
});
});

您需要将单词 iron 替换为您的图像,然后再次设置 html

Working fiddle

关于javascript - 使用逗号分隔符将文本替换为图像标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34042642/

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