admin管理员组文章数量:1435859
<span class="here one-two-sdfs test">click1</span> <br />
<span class="here one-two-3er te3st">click2</span> <br />
<span class="here one-two-sdwrer test">click3</span> <br />
<span class="here one-two-s-ere test">click4</span> <br />
<span class="here one-two-wer-r test">click5</span> <br />
<span class="here one-two test">click6</span> <br />
$('.here').click(function(){
var one-two = ????
alert(one-two);
})
fiddle
i would like -
if i click on click1 then alert show me one-two-sdfs
if i click on click2 then alert show me one-two-3er
if i click on click3 then alert show me one-two-sdwrer
if i click on click4 then alert show me one-two-s-ere
if i click on click5 then alert show me one-two-wer-r
if i click on click6 then alert show me one-two
i would like show class with begin one-two- how can i make it?:)
<span class="here one-two-sdfs test">click1</span> <br />
<span class="here one-two-3er te3st">click2</span> <br />
<span class="here one-two-sdwrer test">click3</span> <br />
<span class="here one-two-s-ere test">click4</span> <br />
<span class="here one-two-wer-r test">click5</span> <br />
<span class="here one-two test">click6</span> <br />
$('.here').click(function(){
var one-two = ????
alert(one-two);
})
fiddle
i would like -
if i click on click1 then alert show me one-two-sdfs
if i click on click2 then alert show me one-two-3er
if i click on click3 then alert show me one-two-sdwrer
if i click on click4 then alert show me one-two-s-ere
if i click on click5 then alert show me one-two-wer-r
if i click on click6 then alert show me one-two
i would like show class with begin one-two- how can i make it?:)
Share Improve this question edited Jul 25, 2012 at 9:38 Luck Mendizo asked Jul 25, 2012 at 9:32 Luck MendizoLuck Mendizo 211 silver badge4 bronze badges 1- 2 Did you try doing any reading on regular expressions and work yourself? – T.J. Crowder Commented Jul 25, 2012 at 9:39
3 Answers
Reset to default 4http://jsfiddle/tMzAH/10/
$('.here').click(function(){
var onetwo = this.className.match(/\bone-two[^\s]*/);
console.log(onetwo[0]);
})
This should work.
$('.here').click(function(){
var one_two = $(this).attr("class").match(/\bone-two\S*/)[0];
alert(one_two);
})
Get the className of the element you clicked. And then split it. You do not need RegEx for this ;)
本文标签: javascriptGet class with regexStack Overflow
版权声明:本文标题:javascript - Get class with regex - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745671362a2669587.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论