<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>test JavaScript</title>
<script src="scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script>
function aa() {
var inputInt = document.getElementById('InputInt');
inputInt.onkeyup = function () {
var num = this.value;
var re =/^[0-9]*[1-9][0-9]*$/;
if (!re.test(num)) {
this.style.color = "red";
} else {
this.style.color = "black";
}
};
//json数组
var jsonText1=
{
"person": [
"jobs",
60
]
}
//alert(jsonText1.person[0]);
//json数组
var jsonText11=
[
"jobs",
60
]
//alert(jsonText11[0]);
//--------------------------------------------------------------
//json对象
var jsonText2=
{
"starcraft": {
"INC": "Blizzard",
"price": 60
}
}
//alert(jsonText2.starcraft.INC);
//json对象
var jsonText22=
{
"INC": "Blizzard",
"price": 60
}
//alert(jsonText22.INC);
//--------------------------------------------------------------
//json对象数组
var jsonText3=
{ "person":[{
"isSuccess":"Y",
"msg":"成功"
},
{
"isSuccess":"N",
"msg":"失败"
}
]
}
//alert(jsonText3.person[0].isSuccess);
//json对象数组
var jsonText33=
[
{
"isSuccess":"Y",
"msg":"成功"
},
{
"isSuccess":"N",
"msg":"失败"
}
]
//alert(jsonText33[0].isSuccess);
$.each(jsonText11, function(index, item){
alert(index+",,,"+item);
});
$.each(jsonText33, function(index, item){
alert(index+",,,"+item.isSuccess);
});
}
</script>
</head>
<body οnlοad="aa()">
<input id="InputInt" type="number" >
</body>
</html>
json的一些demo
最新推荐文章于 2023-05-27 00:00:00 发布