使用Javascript删除字符串的内容
Remove Content of String With Javascript
我从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块。我查看了API调用,但实际上无法通过回调将其删除。
您可以使用regex来替换内容:
var regpattern = /('/'*'s'*'/(.*?)'/'*'s'*'/)/gm
var yourcontent = "include your content here";
yourcontent.replace(regpattern,"");
相关文章:
- 将DOM节点值与字符串Javascript进行比较
- 到UpperCase字符串Javascript中的特定字符索引
- 替换字符串javascript中的所有特殊字符..
- 在数组中查找某些字符串(Javascript)
- 解析特定的字符串Javascript(Node.js)
- 从字符串 JavaScript 中过滤多个正则表达式
- 在字符串 JavaScript 中使用正则表达式替换
- 忽略字符串javascript中的字符
- 如何检查url是否包含多个字符串.Javascript/jquery
- 截断字符串JavaScript
- 计算字符串javascript中的某些单词
- 从'获取本月的最后一天;2015-02-23'字符串(javascript)
- 从字符串javascript中获取键值对
- 从路径字符串 - Javascript 获取所有父路径
- 在字符串Javascript中查找丢失的字母
- AngularJS:如何使所有ng模型都是字符串.JavaScript和长整数
- 将浮点转换为至少有一个小数点的字符串(javascript)
- 替换字符串 JavaScript 中的多个文本
- 检查另一个字符串 JavaScript 中一个字符串是否有任何字符的最佳方法
- 将变量的值包含在 href 字符串 javascript 中