js中字符串和json的相互转换:
json转换成string:JSON.stringify(jsonobject)。
string转换成json:eval('('+Stringmassage+')');
复选框如果选中点击后判断选中状态,如果没选中这改为选中,相反选中改为没选中,并提示(也就是不改变复选框原本状态):
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
function dontChange(input){
if($(input).attr("checked")){
$(input).removeAttr("checked");
alert("之前为未选中状态");
}else{
$(input).attr("checked","checked");
alert("之前为选中状态");
}
}
</script>
</head>
<body>
<input type="checkbox" οnclick="dontChange(this)" checked="checked"/> 测试复选框状态不改变
</body>
注:这里也已写为$(input).attr('checked',true);( $(input).attr('checked',false) )