如何在变更事件中使用无线电?

我有两个单选按钮更改事件我想要更改按钮怎么可能?我的守则


<input type="radio" name="bedStatus" id="allot" checked="checked" value="allot">Allot

<input type="radio" name="bedStatus" id="transfer" value="transfer">Transfer

脚本


<script>

    $(document).ready(function () {

        $('input:radio[name=bedStatus]:checked').change(function () {

            if ($("input[name='bedStatus']:checked").val() == 'allot') {

                alert("Allot Thai Gayo Bhai");

            }

            if ($("input[name='bedStatus']:checked").val() == 'transfer') {

                alert("Transfer Thai Gayo");

            }

        });

    });

</script>


森栏
浏览 360回答 3
3回答

侃侃尔雅

更简单,更清洁的方法是使用@ Ohgodwhy答案的课程<input ... class="rButton"><input ... class="rButton">脚本$( ".rButton" ).change(function() {&nbsp; &nbsp; switch($(this).val()) {&nbsp; &nbsp; &nbsp; &nbsp; case 'allot' :&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("Allot Thai Gayo Bhai");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; case 'transfer' :&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("Transfer Thai Gayo");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery