layui之獲取form表單的radio
阿新 • • 發佈:2018-11-12
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);