首页 > 代码库 > Json操作

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="http://www.mamicode.com/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="http://www.mamicode.com/+ n +"]";                $(o).attr("checked", true);            });        }    </script></head><body>    <input type="button" value="http://www.mamicode.com/验证" onclick="showInfo()" />    <input type="button" value="http://www.mamicode.com/设置" onclick="setCheck()" />    <div>        <ul>            <li>                <input type="checkbox" value="http://www.mamicode.com/李四" id="checkbox2" onclick="checkMe(this)" info=‘{"年龄":"22"}‘ /><label for="checkbox2">李四</label></li>            <li>                <input type="checkbox" value="http://www.mamicode.com/王五" id="checkbox3" onclick="checkMe(this)" info=‘{"年龄":"33"}‘ /><label for="checkbox3">王五</label></li>            <li>                <input type="checkbox" value="http://www.mamicode.com/赵六" id="checkbox4" onclick="checkMe(this)" info=‘{"年龄":"44"}‘ /><label for="checkbox4">赵六</label></li>            <li>                <input type="checkbox" value="http://www.mamicode.com/李三" id="checkbox5" onclick="checkMe(this)" info=‘{"年龄":"22"}‘ /><label for="checkbox5">李三</label></li>        </ul>    </div></body></html>

 

Json操作