Get part of a string using JavaScript/jQuery
I have a string, for example testserver\sho007
, how do I use jQue开发者_JAVA百科ry to return only sho007
?
You can do it simply with javascript
var my_string="testserver\sho007";
var left_side=my_string.split("\\")[0];
var right_side=my_string.split("\\")[1];
edited to add the double slash as Eric mentioned
You may use
text.substring(fromindex,toindex)
Use Regular Expressions if you are sure that the text you want is going to be after the slash.
split the string using "\" and get the position [1], always start with [0]
exp:
html:
<a class='test'>testserver\sho007</a>
js:
$(document).ready(function(){
var a = $(".test").text();
var aResult = a.split("\\")[1];
});
testserver = [0]
sho007 = [1]
精彩评论