Get value from a string after a special character

后端 未结 4 695
生来不讨喜
生来不讨喜 2021-01-30 10:26

How do i trim and get the value after a special character from a hidden field The hidden field value is like this

Code



        
4条回答
  •  暖寄归人
    2021-01-30 10:54

    You can use .indexOf() and .substr() like this:

    var val = $("input").val();
    var myString = val.substr(val.indexOf("?") + 1)
    

    You can test it out here. If you're sure of the format and there's only one question mark, you can just do this:

    var myString = $("input").val().split("?").pop();
    

提交回复
热议问题