radaio: radio button
html:
<input type="radio" name="city" value="广州" id="myCheck"/> 广州
Grouped by Name, you need to be initialized when a group of selected radio can only select a value, without the need to add the checked attribute assignment.
disabled: setting is enabled elements: the assignment may not require, or disabled = 'disabled'
JUDGMENT:
Realize the value of the element type: radio
checked = true / false setting selected
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> function check() { //document.getElementById("myCheck").addAttribute("checked","checked"); document.getElementById("myCheck").checked = true;uncheck () { function }recommended usage// //document.getElementById("myCheck").removeAttribute("checked"); document.getElementById("myCheck").checked = false; } function getcheck() { alert(document.getElementById("myCheck").checked); // 输出 boolean 值 true 或者false } function doDisabled(obj) { var cb = document.getElementById("myCheck"); console.log(cb.disabled); if(cb.disabled) { // cb.disabled=null; cb.disabled = false; cb.removeAttribute("disabled"); obj.value = "禁用checkbox"; } else { //cb.setAttribute("disabled","disabled"); cb.disabled = true; //cb.disabled="disabled"; obj.value = ""Enable the CheckBox; } } // get the selected value
function getCheckValue()
{
var cbs=document.getElementsByName("city");
var vchecked="";
for(var i=0;i<cbs.length;i++)
{
if(cbs[i].checked){
vchecked=cbs[i].value;
}
}
alert(vchecked);
}
</script> </head> <body> <input type="radio" disabled="disabled" checked="checked" name="city" value="上海" /> 上海 <input type="radio" name="city" value="广州" id="myCheck"/> 广州 <input type="radio" name="city"the INPUT<Beijing />= "Beijing"value of the type = "Radio" name = "City" value = "Shenzhen" /> Shenzhen < the INPUT of the type = "the Button" onclick = "the Check ()" value = "the checkbox" /> < the INPUT of the type = "the Button" the onclick = "uncheck ()" value = "check box is deselected" /> < INPUT type = "Button" the onclick = "GetCheck ()" value = "obtain the selected checkboxes" /> < INPUT type = "button" onclick="doDisabled(this)" value="禁用radio" /> <input type="button" onclick="getCheckValue()" value="获取选择的值"/> </body> </html>
jquery
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="../javascript/jquery-1.10.2.js"></script> <script type="text/javascript"> function check() { $("#myCheck").prop("checked",true) } function uncheck() { $("#myCheck").prop("checked",false); } function getcheck() { //alert(document.getElementById("myCheck").checked); // 输出 boolean 值 true 或者false alert($("#myCheck").prop("checked")); } function doDisabled(obj) { // debugger; if($("#myCheck").prop("disabled")) { $("#myCheck " ) .prop ( " Disabled " , to false ); obj.value = " Disable checkbox " ; } the else { $ ( " #myCheck " ) .prop ( " Disabled " , to true ); obj.value = " Enable checkbox " ; } } // Get the value of the selected function getCheckValue() { Alert ($ ( "input[name='city']:checked").eq(0).val()); } </script> </head> <body> <form> <input type="radio" id="myCheck" name="city" value="上海" name="city" /> 上海 <input type="radio" name="city" value="北京" name="city" the INPUT<Beijing />type="radio" name="city" value="深圳" name="city" /> 深圳 <input type="radio" name="city" value="广州" name="city" /> 广州 <input type="button" onclick="check()" value="选定复选框" /> <input type="button" onclick="uncheck () " INPUT</>=" check box is deselected "value type = "Button" the onclick = "GetCheck ()" value = "obtain the selected checkboxes" /> < INPUT type = "Button" the onclick = "doDisabled (the this)" value = "Disable CheckBox" /> < INPUT type = "Button" the onclick = "getCheckValue ()" value = "acquires the value of the selected" /> </ form > </ body > </ HTML >