Json操作

<!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>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。