使用 jQuery 进行部分匹配?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6488942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 20:57:14  来源:igfitidea点击:

Making partial matches with jQuery?

jqueryjquery-selectors

提问by Mirage

I want to find all input boxes with idcontaining _date

我想找到所有id包含的输入框_date

My code is like this:

我的代码是这样的:

<input type="text" name="creation_date" id="id_creation_date" />

Can I use regex for that? Do I need to install something extra for regex to work with jQuery?

我可以为此使用正则表达式吗?我是否需要为正则表达式安装额外的东西才能使用 jQuery?

回答by jerluc

I'm thinking of one of these...

我在想一个的这些...

$('input[id*="_date"]').css('background-color', 'red');

$('input[id*="_date"]').css('background-color', 'red');

回答by Bharat Patil

If you just want to check ending with "_date" rather than containing "_date" you can use

如果您只想检查以“_date”结尾而不是包含“_date”,则可以使用

$('input[id$="_date"]')