首页 > 代码库 > 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操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。