截取指定字符前后字符串
作者:互联网
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>分割字符串</title>
</head>
<body>
<input type="text" class="int">
<button onclick="getStr()">截取</button>
</body>
<script type="text/javascript">
var int=document.querySelector('.int');
function getStr() {
var string=int.value;
if(string.indexOf("省")>-1){
var str="省";
var str_before = string.split(str)[0];
var str_after = string.split(str)[1];
console.log('前:' + str_before + ' - 后:' + str_after);
}
else if(string.indexOf("自治区")>-1){
var str1="自治区";
var str_before = string.split(str1)[0];
var str_after = string.split(str1)[1];
console.log('前:' + str_before + ' - 后:' + str_after);
}
}
</script>
</html>
更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/120074584
标签:字符,string,截取,after,var,split,str,字符串,before 来源: https://www.cnblogs.com/wangchuanxinshi/p/16521668.html