目录
1.数组的值保留两位小数
var y_store = data.y_store; //获取后台的数组
var x = 0;
var len = y_store.length
while(x < len){
y_store[x] = y_store[x].toFixed(2);
x++
}
2.JS获取url上面的值
window.location.href="update_bankCard.html?id="+id;
window.location.href='apackageIn.html?id='+id+'&text='+text;
function GetQueryString(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);//search,查询?后面的参数,并匹配正则
if(r!=null)return unescape(r[2]);
return null;
}
var id = GetQueryString("id");
var text = GetQueryString("text");
console.log(id)
3.判断一个数组中的数据是否也存在于另一个数组中!
<script>
var menuIds = ["34", "1", "35", "2", "99", "88"]
var newmenuid = ["34", "1", "35", "2", ]
for (var s in newmenuid) {
for (var x in menuIds) {
if (newmenuid[s] == menuIds[x]) {
console.log("存在", newmenuid[s])
} else {}
}
}
</script>