[JQ权威指南]JQ操作JSON数据



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>操作JSON数据title>
        <script type="text/javascript"  src="Jscript/jquery-1.4.2.min.js">
    script>
    <style type="text/css">
           body{font-size:13px}
           .iframe{width:320px;border:solid 1px #666}
           .iframe .title{padding:5px;background-color:#eee;}
           .iframe .content{padding:8px; font-size:12px;}
           .btn {border:#666 1px solid;padding:2px;width:80px;filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);}
    style>
    <script type="text/javascript">
        var strInfo = "{ 'name':  '龚德辉','sex': '男', 'email':'[email protected]','date':'1349340837359'}";
        var strInfo2 = "{ 'name':  'dezai','sex': '女', 'email':'[email protected]','date':'1352340837768'}";

    $(function () {
        var strV0 = "原始数据";
        var strV1 = "变化数据";
        var strHTML = "";

        $("#Button1").click(function () {


            var objInfo2 = eval('(' + strInfo2 + ')'); //加上圆括号的目的是迫使eval函数在处理JavaScript代码的时候强制将括号内的表达式(expression)转化为对象,而不是作为语句(statement)来执行

            if ($(this).val() == strV1) { //变化数据

                strHTML += "姓名:" + objInfo2.name + "
"
; strHTML += "性别:" + objInfo2.sex + "
"
; strHTML += "邮箱:" + objInfo2.email + "
"
; strHTML += "时间:" + objInfo2.date + "
"
; strHTML += "
"
; } if ($(this).val() == strV0) { //原始数据 var objInfo = eval('(' + strInfo + ')'); strHTML += "姓名:" + objInfo.name + "
"
; strHTML += "性别:" + objInfo.sex + "
"
; strHTML += "邮箱:" + objInfo.email + "
"
; strHTML += "时间:" + objInfo.date + "
"
; strHTML += "
"
; $("#Tip").html(strHTML); $(this).val(strV1) } else { $(this).val(strV0) } $("#Tip").html(strHTML); }); });
script> head> <body> <div class="iframe"> <div class="title"> <input id="Button1" type="button" class="btn" value="原始数据" /> div> <div class="content"> <div id="Tip">div> div> div> body> html>

[JQ权威指南]JQ操作JSON数据_第1张图片

你可能感兴趣的:(前端设计,JQuery)