我有一个字符串,例如testserver\\sho007
,如何使用jQuery只返回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)
如果您确定所需的文本将在斜杠之后,请使用正则表达式。
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.