首页 > Web开发 > 详细

Json操作

时间:2014-12-01 00:36:01      阅读:273      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="Js/jquery-1.9.1.js"></script>
    <script type="text/javascript">
        var Datas = JSON.parse("{\"data\":{}}");
        function checkMe(obj) {
            var key = $(obj).attr("value");
            var keyInfo = $(obj).attr("info");
            for (var i in Datas) {
                if (i == key)
                    delete Datas[i];
                else
                    $(Datas).attr(key, keyInfo);
            }
        }
        function showInfo() {
            for (var i in Datas)
                alert(i);
        }
        function setCheck() {
            var argss = ["李四", "王五", "李三"];
            $.each(argss, function (i, n) {
                var o = "input:checkbox[value=" + n + "]";
                $(o).attr("checked", true);
            });
        }
    </script>
</head>
<body>
    <input type="button" value="验证" onclick="showInfo()" />
    <input type="button" value="设置" onclick="setCheck()" />
    <div>
        <ul>
            <li>
                <input type="checkbox" value="李四" id="checkbox2" onclick="checkMe(this)" info=‘{"年龄":"22"}‘ /><label for="checkbox2">李四</label></li>
            <li>
                <input type="checkbox" value="王五" id="checkbox3" onclick="checkMe(this)" info=‘{"年龄":"33"}‘ /><label for="checkbox3">王五</label></li>
            <li>
                <input type="checkbox" value="赵六" id="checkbox4" onclick="checkMe(this)" info=‘{"年龄":"44"}‘ /><label for="checkbox4">赵六</label></li>
            <li>
                <input type="checkbox" value="李三" id="checkbox5" onclick="checkMe(this)" info=‘{"年龄":"22"}‘ /><label for="checkbox5">李三</label></li>

        </ul>
    </div>
</body>
</html>

 

Json操作

原文:http://www.cnblogs.com/-Apple/p/4133988.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!