<!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>