layui之获取form表单的radio
form表单是这样的:
<div class="layui-form-item"> <label class="layui-form-label">单选框</label> <div class="layui-input-block"> <input type="radio" name="sex" value="男" title="男"> <input type="radio" name="sex" value="女" title="女" checked> </div> </div>
用jquery获取radio如下:
var value = $("input[name='sex']:checked").val();
console.log(value);
同理form表单里面的checkbox也是一样的
<div class="layui-form-item"> <label class="layui-form-label">复选框</label> <div class="layui-input-block"> <input type="checkbox" name="like[write]" title="写作"> <input type="checkbox" name="like[read]" title="阅读" checked value="阅读"> <input type="checkbox" name="like[dai]" title="发呆"> </div> </div>
var check = $("input[name='like[read]']:checked").attr("title");
console.log(check);