gpt4 book ai didi

javascript - JQuery 如何替换文本区域内的字符串?

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

当前文本区域:

<textarea id="event_content">
This text area could be full of information..www.london2012.com
And might contain upto 5 links that all need updating.
www.rio2016.org

Link already converted. this should be left.
<a href="http://www.thetimes.co.uk" target="_blank">www.thetimes.co.uk</a>
</textarea>
<小时/>

jquery 之后所需的文本区域:所有链接都将被清理/替换为标签和目标属性

<textarea id="event_content">
This text area could be full of information
<a href="http://www.london2012.com" target="_blank">www.london2012.com</a>
And might contain upto 5 links that all need updating.
<a href="http://www.rio2016.org" target="_blank">www.rio2016.org</a>

Link already converted. this should be left.
<a href="http://www.thetimes.co.uk" target="_blank">www.thetimes.co.uk</a>
</textarea>
<小时/>

2012 年 7 月 21 日 - Ωmega's代码很有效,谢谢,但是可以通过保留已经转换的链接来改进吗?

最佳答案

我相信您正在寻找类似的东西(点击here来测试这个 fiddle ):

$('#event_content').val(
$('#event_content').val().replace(/\b(http(s|):\/\/|)(www\.\S+)/ig,
"<a href='http\$2://\$3' target='_blank'>\$3</a>"));

关于javascript - JQuery 如何替换文本区域内的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11581372/

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