开发者

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);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜