Making partial matches with jQuery?

2019-01-23 02:20发布

问题:

I want to find all input boxes with id containing _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?

回答1:

I'm thinking of one of these...

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



回答2:

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

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