1. 程式人生 > >jquery 提取選中的radio的值

jquery 提取選中的radio的值

原始碼:

    <div class="panel" style="border:0">
        <div class="col-md-12" style="margin-top: 1em;margin-bottom: 2em;">
            <div class="col-md-3">
                <input type="radio" name="state" value="0" id="ostate">
                <span>已經解決</span>
            </div>
            <div class="col-md-3">
                <input type="radio" name="state" value="1" id="ostate">
                <span>入知識庫</span>
            </div>
            <div class="col-md-3">
                <input type="radio" name="state" value="2" checked id="ostate">
                <span>尚未解決</span>
            </div>
            <div class="col-md-3">
                <input type="radio" name="state" value="3" id="ostate">
                <span>分配工單</span>
            </div>
        </div>
        <div class="col-md-12">
            <input type="text" name="cont" id="cont" class="col-lg-12 form-control"
                   style="height: 55px ">
        </div>
    </div>
</div>

方法:

var state1=$('input:radio:checked').val();
var state2=$("input[type='radio']:checked").val();
var state3=$("input[name='state']:checked").val();