jQuery仅匹配来自div的ID的一部分 [英] jQuery match only part of id from div

查看:305
本文介绍了jQuery仅匹配来自div的ID的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天晚上我遇到了异常情况.

I ran into an unusual situation yesterday night.

我只需要匹配ID的一部分.让我用一个例子来澄清大家

I need to match only part of id. Let me clear you all with an example

我的divs很少

<div id="sales_info_1">... ...... ...... ...... ...</div>
<div id="sales_info_2">... ...... ...... ...... ...</div>
<div id="sales_info_3">... ...... ...... ...... ...</div>

和jQuery一样

jQuery("div#dont_know_what_to_write_here").bind("click", function(){
    ... ...... ...... ...... ...
});

我只需要匹配 sales_info ,而忽略_1,_2或_anything,有人可以建议我如何实现此目标吗?

I need to match only sales_info, ignoring _1, _2 or _anything, can anyone suggest me how to achieve this?

谢谢

推荐答案

您可以使用开始于"选择器:

$('div[id^="sales_info_"]')

我宁愿建议您为元素选择一个唯一的类名.

I'd rather recommend you use a unique class name for your elements that you can select on though.

这篇关于jQuery仅匹配来自div的ID的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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