<script type="text/javascript">
/*
string 字符串;
str 指定字符;
split(),用于把一个字符串分割成字符串数组;
split(str)[0],读取数组中索引为0的值(第一个值),所有数组索引默认从0开始;
*/
function getStr(string,str){
var str_before = string.split(str)[0];
var str_after = string.split(str)[1];
alert('前:'+str_before+' - 后:'+str_after);
}
</script>
例
var st = "javascript:zhifu('index.php?s=/addon/xxxx/Alipay/index/cartid/1964/addid/162/invid/648/couponsid/11/paytype/2/type/3/fu/38.8/giveid/70,/givenum/1,/voucher//default',162)";
var before_str = getStr(st,"giveid");
alert(before_str);
结果:
javascript:zhifu('index.php?s=/addon/xxxx/Alipay/index/cartid/1964/addid/162/invid/648/couponsid/11/paytype/2/type/3/fu/38.8/