//For a string before and after a single character in the conceit
<!doctype html> <html> <head> <meta charset="utf-8"> <title>split string</title> </head> <script type="text/javascript"> /* string string; str specifies the character; split(), used to split a string into an array of strings; split(str)[0], read the value with index 0 in the array (the first value), all array indexes start from 0 by default; */ function getStr(string,str){ var str_before = string.split(str)[0]; var str_after = string.split(str)[1]; alert('前:'+str_before+' - 后:'+str_after); } </script> <body> <input type="button" onClick="getStr('string','r');" value="获取值" /> </body> </html>