gpt4 book ai didi

jquery - 如何使用 jQuery 将第一个和第二个单词包裹成两个斜体

转载 作者:行者123 更新时间:2023-12-01 03:06:51 25 4
gpt4 key购买 nike

这是我的代码:

jQuery('.n2-ss-item-content').each(function(){
var me = jQuery(this);
me.html(me.html().replace(/^(\w+)/, '<i>$1</i>'));
});

HTML 输出显示如下:

<i>Majesty</i> Purple | 24” w x 20” h | SOLD

假设应该是这样的:

<i>Majesty Purple</i> | 24” w x 20” h | SOLD

最佳答案

jQuery('.n2-ss-1item1').each(function(){
var me = jQuery(this);
me.html(me.html().replace(/^([^|]+)/, '<i>$1</i>'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p class="n2-ss-1item1">Majesty Purple | 24” w x 20” h | SOLD</p>

<p class="n2-ss-1item1">Majesty Blue | 24” w x 20” h | SOLD</p>

关于jquery - 如何使用 jQuery 将第一个和第二个单词包裹成两个斜体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55919782/

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