var a={"name":"tom","sex":"男","age":"24"};
var b='{"name":"Mike","sex":"女","age":"29"}';
var aToStr=JSON.stringify(a);
var bToObj=JSON.parse(b);
alert(aToStr); //string
alert(
);//object
js获取对象里所有的key和key值。
var obj = {
A:2
,B:"Ray"
,C: true
,D: function(){}
}
for(
var key
in obj){
console.log(key,obj[key])
console.log(key,obj[key])
}
------------------------------------------------------------------------------------------------------------------------------------------------------------
解决在移动端上alert 弹出域名的问题
<script type="text/javascript">
//在alert之前加入这段代码即可
window.alert = function(name){
var iframe = document.createElement("IFRAME");
iframe.style.display="none";
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
window.frames[0].window.alert(name);
iframe.parentNode.removeChild(iframe);
}
alert(111); //亲测有效
</script>