$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - Get class with regex - Stack Overflow|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Get class with regex - Stack Overflow

matteradmin13PV0评论
<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
Add a ment  | 

3 Answers 3

Reset to default 4

http://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 ;)

Post a comment

comment list (0)

  1. No comments so far