开发者

jquery - get id attr of (this)

开发者 https://www.devze.com 2023-02-19 10:22 出处:网络
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

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

精彩评论

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