jQuery string split the string after the space using split() method

前端 未结 3 1064
眼角桃花
眼角桃花 2021-02-07 13:27

my code

  var str =$(this).attr(\'id\');

this will give me value == myid 5

   var str1 = myid
   var str2 = 5         


        
3条回答
  •  隐瞒了意图╮
    2021-02-07 13:41

    One line solution:

    //
    var postId = this.id.split('mypost-')[1] ); //better solution than the below one!

    -OR-

    //
    var postId = $(this).attr('id').split('mypost-')[1];

提交回复
热议问题