<input id="ctl00_PlaceHolderMain_RadButtonMango_ClientState" name="ctl00_PlaceHolderMain_RadButtonMango_ClientState" type="hidden" value="{"text":"Mango","value":"Mango","checked":true,"target":"","navigateUrl":"","commandName":"","commandArgument":"","autoPostBack":true,"selectedToggleStateIndex":0,"validationGroup":null,"readOnly":false}" autocomplete="off">
在这种情况下,我们怎样才能找到已检查的值
我能够找到所有值但是如何检查
$("#ctl00_PlaceHolderMain_RadButtonTrial_ClientState").attr("value")
{
"text": "Trial",
"value":"Trial",
"**checked":true**,
"target":"",
"navigateUrl":"",
"commandName":"",
"commandArgument":"",
"autoPostBack":true,
"selectedToggleStateIndex":0,
"validationGroup":null,
"readOnly":false}"
}
答案 0 :(得分:0)
首先,您需要一个结束标记:
<input></input>
第二,你不能这样做:
value="{"text":"Mango","value":"Mango","checked":true,"target":"","navigateUrl":"","commandName":"","commandArgument":"","autoPostBack":true,"selectedToggleStateIndex":0,"validationGroup":null,"readOnly":false}"
双引号相互冲突。尝试用单引号将它全部包装起来:
value='{"text":"Mango","value":"Mango","checked":true,"target":"","navigateUrl":"","commandName":"","commandArgument":"","autoPostBack":true,"selectedToggleStateIndex":0,"validationGroup":null,"readOnly":false}'
现在要解决实际问题,你需要将value属性中的字符串解析为json,然后获取checked的值:
var parsedJson = JSON.parse($("#ctl00_PlaceHolderMain_RadButtonMango_ClientState").attr('value'));
document.write(parsedJson.checked);