gpt4 book ai didi

javascript - 使用 jQuery 在第一行后包装括号文本

转载 作者:行者123 更新时间:2023-11-30 19:24:53 25 4
gpt4 key购买 nike

我有这个

<p>
<strong>FITZGERALD</strong> (CONT’D)<br>
Shut up, boy, you don’t get no say in this.<br>
(back to Henry)<br>
And in case you hadn’t noticed, Captain, we’re seventeen men short of what we were.
(off the wounded trapper)<br>
Eighteen before long.
</p>

我要加类.wi-dialog对于 p并将每个文本括在括号中 ( )喜欢<span class="wi-remark">( )</span>但先<br>之后

所以我的段落看起来像这样

<p class="wi-dialog">
<strong>FITZGERALD</strong> (CONT’D)<br>
Shut up, boy, you don’t get no say in this.<br>
<span class="wi-remark">(back to Henry)</span><br>
And in case you hadn’t noticed, Captain, we’re seventeen men short of what we were.
<span class="wi-remark">(off the wounded trapper)</span><br>
Eighteen before long.
</p>

我无法解决第一行的问题。这是我的代码

$(document).ready(function(){
var dialog = $( "p:has(strong)" ).addClass( "wi-dialog" );

dialog.html(function(i, v) { return v.replace(/.*?(\(.*?\)).*?/g, '<span class="wi-remark">$&</span>') });
})

最佳答案

这是我的解决方案。

$(document).ready(function(){
var dialog = $( "p:has(strong)" ).addClass( "wi-dialog" );
dialog.html(function(i, v) { return v.replace(/(?<=\n)\s*(\(.*?\)).*?/g, '<span class="wi-remark">$&</span>') });
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>
<strong>FITZGERALD</strong> (CONT’D)<br>
Shut up, boy, you don’t get no say in this.<br>
(back to Henry)<br>
And in case you hadn’t noticed, Captain, we’re seventeen men short of what we were.
(off the wounded trapper)<br>
Eighteen before long.
</p>

关于javascript - 使用 jQuery 在第一行后包装括号文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57023664/

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