如何使用jQuery检查字符串的开头? [英] How can I check the start of a string with jQuery?

查看:222
本文介绍了如何使用jQuery检查字符串的开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有:

if ($(this).data('action') == "Editing" || $(this).data('action') == "Create") {
    tinyMCE.init(window.tinyMCEOptions);
}

我需要做的是检查创建菜单"或创建参照".基本上所有以创建"开头的数据.

What I need to do is to check for "Create Menu" or "Create Referene". Basically any data starting with the word "Create".

我该如何使用通配符?

推荐答案

如果这些是元素的属性(据我们所知,它是this),则可以使用以下方法:

If these are attributes of the element (as far as we know, it's this), then you can use this:

if( $(this).is("[data-action^='Create']") ){
    tinyMCE.init(window.tinyMCEOptions);
}

$(this).is("[data-action^='Create']")将检查返回元素data-action属性是否以字符串Create 开头.它将返回truefalse.我们正在使用属性以选择器开头.

$(this).is("[data-action^='Create']") will check if the data-action attribute of the returned element(s) starts with the string Create. It will return true or false. We're using the attribute starts with selector.

这篇关于如何使用jQuery检查字符串的开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆