-1
<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);
    })​

小提琴

我想 -

如果我点击click1然后警报显示我一二自卫队

如果我点击click2然后警报告诉我one- 2-3er

如果我点击click3然后警报告诉我one-two-sdwrer

如果我点击click4然后警报告诉我one-two-s-ere

如果我点击click5然后警报告诉我one-two-wer-r

如果我点击click6然后提醒我一二

我想以一二开始的表演课- 我该怎么做?:)

4

3 回答 3

4

http://jsfiddle.net/tMzAH/10/

$('.here').click(function(){
    var onetwo = this.className.match(/\bone-two[^\s]*/);
    console.log(onetwo[0]);
})
于 2012-07-25T09:38:48.613 回答
3

应该有效。

$('.here').click(function(){
    var one_two = $(this).attr("class").match(/\bone-two\S*/)[0];
    alert(one_two);
    })​
于 2012-07-25T09:39:02.040 回答
0

获取您单击的元素的类名。然后拆分它。您不需要 RegEx ;)

于 2012-07-25T09:37:13.823 回答