學會使用indexOf()和substr()和split()取字符串特定值
點我點我
eg:
<script>
var transferId;
transferId = parseInt(urlname.substr(urlname.indexOf("=")+1,urlname.length-1));
//
transferId = parseInt(urlname.split("/z/").[1]);
//split()方法返回的是一個數組 所以要用[]取到
</script>
eg:
var str1= "http://z.sina.com.cn/z/19980127";
console.log(str1.split("/z/"));
// ["http://z.sina.com.cn", "19980127"]
console.log(str1.split("/z/")[1]);
// 19980127
==因爲split()方法返回的是數組==
var str2 = "http://z.sina.com.cn/maker/?id=19980127";
console.log(str2.substr(str2.indexOf("=")+1,str2.length-1));
//19980127