我需要使用Jquery从字符串中获取certian部分

edw*_*ard -1 html javascript jquery

我需要jsmith从以下元素alt属性中获取该部分

<img src="http://www.test.com" class="img-thumbnail" alt="John Smith (jsmith)">
Run Code Online (Sandbox Code Playgroud)

所以我正在运行这个

$('.img-thumbnail').attr('alt');
Run Code Online (Sandbox Code Playgroud)

这给了我

"John Smith (jsmith)"
Run Code Online (Sandbox Code Playgroud)

我需要把'jsmith'部分拿出来

有任何想法吗?

Utk*_*xit 6

试试这个

$('.img-thumbnail').attr('alt').match(/\(([^)]+)\)/)[1]
Run Code Online (Sandbox Code Playgroud)

请注意,这仅在您希望将文本放在括号内时才有效. FIDDLE.希望这可以帮助