gpt4 book ai didi

javascript - 如何检查字符串是否以 iFrame 开头?

转载 作者:行者123 更新时间:2023-12-01 01:07:36 24 4
gpt4 key购买 nike

我们正在构建一个新闻源应用程序,其中一些帖子包含 iframed youtube 视频,而其他帖子则不包含。为了使视频具有响应能力,我们将 div 包装在具有“视频容器”类的 div 中。但是,我们只希望当数据字符串以 开头时该类处于事件状态。

这适用于 v-for 循环中的项目。

使用vuejs,我们如何检查数据字符串是否包含“iframe”?

<v-card-text class="pt-1 pb-0">
<div :class="{'video-container':
(videoCheck(props.item.content) )}">
<p v-html="props.item.content"></p>
</div>
</v-card-text>

以及方法:

videoCheck: function(item){
var substring = "<iframe>"
return item.includes(substring)
},

最佳答案

据我所知,向后兼容的解决方案是使用 indexOf :

返回 item.indexOf(substring) == 0;

还有startsWith在所有最新的浏览器中:

返回 item.startsWith(substring);

关于javascript - 如何检查字符串是否以 iFrame 开头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55484948/

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