gpt4 book ai didi

javascript - 使用 Javascript 删除字符串内容

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

我正在从 API 中提取新闻/体育/科技文章并将这些文章填充到我的网页中。这里的问题是,在我的许多文章中,我不断收到包含 javascript 的文本字符串。

示例,我们的一些文章的片段:

 Viewers can also choose to ignore the teaser that appears, and it will go away allowing you to watch the video uninterrupted. /* */ if (ads.isMobile()) { (function(window,$){ window.TechCrunch.loader.on('tc_ads_wrapper_omniture', function(){ if ( !window.ads.isAdPageSet ){ if ( typeof window.adSetAdURL == 'function' ) { window.adSetAdURL('/wp-content/themes/vip/techcrunch-2013/_uac/adpage.html'); window.ads.isAdPageSet = true; } } window.htmlAdWH('348-14-15-135e', "300", "115", 'f', 'adsDivafa83e683e'); }); }(this,this.jQuery)); } /* */ YouTube notes that over time, the plan is to not only help creators provide this enriched experience to viewers,

另一篇文章:

Their best strategy, I believe, is to communicate emotions rather than specific nouns and verbs. /* */ if (ads.isMobile()) { (function(window,$){ window.TechCrunch.loader.on('tc_ads_wrapper_omniture', function(){ if ( !window.ads.isAdPageSet ){ if ( typeof window.adSetAdURL == 'function' ) { window.adSetAdURL('/wp-content/themes/vip/techcrunch-2013/_uac/adpage.html'); window.ads.isAdPageSet = true; } } window.htmlAdWH('348-14-15-135e', "300", "115", 'f', 'adsDiv186350d01b'); }); }(this,this.jQuery)); } /* */ In a classic perceptual psychology experiment, pairs of strangers were asked to communicate emotions through touch alone. The “encoder” was given one of 12 different emotions, then touched the “decoder’s” forearm through a curtain.

还有另一个:

“We’re known for digital content advertising, but close to 40% of our business has been mobile commerce for quite some time, in areas like user acquisition and monetization outside of the basic sales transaction.” /* */ if (ads.isMobile()) { (function(window,$){ window.TechCrunch.loader.on('tc_ads_wrapper_omniture', function(){ if ( !window.ads.isAdPageSet ){ if ( typeof window.adSetAdURL == 'function' ) { window.adSetAdURL('/wp-content/themes/vip/techcrunch-2013/_uac/adpage.html'); window.ads.isAdPageSet = true; } } window.htmlAdWH('348-14-15-135e', "300", "115", 'f', 'adsDivafa83e683e'); }); }(this,this.jQuery)); } /* */ The strategic nature of the investment from Market Tech was part of the reason why Lin said Glispa gave a nod to giving up a stake of the company.

有没有办法在页面填充数据之前排除那些以 /* */ 开头和结尾的 JavaScript block 。我查看了 API 调用,但没有办法通过回调实际删除它。

最佳答案

您可以使用正则表达式来替换内容:

var regpattern = /(\/\*\s\*\/(.*?)\/\*\s\*\/)/gm

var yourcontent = "include your content here";

yourcontent.replace(regpattern,"");

关于javascript - 使用 Javascript 删除字符串内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29148066/

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