jquery - get id attr of (this)
An anchor tag similar to this is clicked.
<a href="go.php?id=3aaa">Click Me</a>
$(this)[0]
contain开发者_StackOverflows a string similar to http://localhost/www/go.php?3aaa
I wish to strip the "3" and "aaa" (values change according to what is clicked) into their own variables and test for their values.
Try this:
var match = $(this)[0].match(/\?(\d{1,})(\w*)/);
then match[1]
has the digit (3 like above) and match[2]
has the string (aaa like above);
精彩评论