How do I go about using regex to match any anchor whos href starts with "#t_row_" ?
For example, one of the anchors looks like: <a href=开发者_StackOverflow社区"#t_row_234567890">Link</a>
Currently I have:
$('a[href*=#]')each(function() {
Cheers
For this exact case, use the jQuery Attribute Starts With selector:
$('a[href^="#t_row"]')
Alternatively, in a more general case, you can filter()
any set of elements based on arbitrary JS code. In this case it would be:
$('a').filter(function(i){ return /^#t_row/.test(this.href); });
No need to use a regex. $('a[href^="#t_row_"]')
will do the job.
http://api.jquery.com/attribute-starts-with-selector/
What you need is
$('a[href^="#t_row_"]')
http://api.jquery.com/attribute-starts-with-selector/
精彩评论