如何检查ID名称是否包含某些模式? [英] How to check id name if contains some pattern?

查看:82
本文介绍了如何检查ID名称是否包含某些模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery,并且循环像这样:

I am using jquery and I am looping like:

$("span").each(function (index) {
    var idname = $(this).attr('id');
    $("#" + idname).click(function () {
        window.location.href = "http://" + $(this).attr('id') + "lin.gw";
    });

}); //end for click attachment to button

我想遍历id包含*raid*的元素.它的语法是什么?

I would like to loop over the elements where id contains *raid*. What is the syntax for it?

推荐答案

使用属性-包含选择器:

$("span[id*=raid]").click(function(){
    window.location.href = "http://"+ this.id +"lin.gw"; 
});

这篇关于如何检查ID名称是否包含某些模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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