var MilageBeginNum = str.indexOf("allocatemileage=")+"allocatemileage=".length;
//你写死的17是不对的.其实对于你这个问题, 用正则表达式是最简单的确解决办法了
<SCRIPT LANGUAGE="JavaScript">
<!--
var str="allocationid=7742;deptid=9255;allocatemileage=5;allocatepark=0;allocaterec=0;";/allocationid=([^=;]*)/.test(str);
allocationid = RegExp.$1;
alert("allocationid = "+ allocationid);/allocatemileage=([^=;]*)/.test(str);
allocatemileage = RegExp.$1;
alert("allocatemileage = "+ allocatemileage);
//-->
</SCRIPT>

解决方案 »

  1.   

    var str="allocationid=7742;deptid=9255;allocatemileage=5;allocatepark=0;allocaterec=0;";
      function getUrlParam(name){
        var reg = new RegExp("(^|;)"+ name +"=([^;]*)(;|$)");
        var r = str.match(reg);
        if (r!=null) return unescape(r[2]); return null;
      }
      alert("allocatemileage="+getUrlParam("allocatemileage"));
      

  2.   

    cxz7531(大花猫)  拜托, 回复之前最好测试一下自己写的代码, 不要犯一些低级错误, 还有就是别人的好代码要消化吸收后再用呀. (var r = str.match(reg); //你这个 str 是哪里冒出来的??)
      

  3.   

    其实,梅花雪的MzTreeView里面不是写了一个专门处理这种字符串的函数getAttribute(差不多吧)嘛,拿过来可以直接用了,听说,那个函数,管用,而且还是免费的呢!!