📜  如何获取 on 和 off 状态的值 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:13.140000             🧑  作者: Mango

代码示例1
//FOR CHECK BOX / SWITCH
var stateValue = $("#yourInputElement").is(":checked");
// will be set to the element value if checked (ON) or will be null otherwise
var stateValue = $("#yourInputElement").is(":checked") ? $("#yourInputElement").val() : null;

//FOR RADIO
var stateValue = $(":radio:checked", radioParentContainer).val();