两个或更多" Radio"按钮组我没有正常工作

时间:2015-03-31 06:33:46

标签: button radio

我有这段代码

function dataSelect23124() {
  $( "#result1" ).html( $('input:checked').val() + " is checked!" );
};

function dataSelect23123() {
  $( "#result" ).html( $('input:checked').val() + " is checked!" );
};

以下是JSFiddle

但我遇到了一个问题,让它发挥作用。

1 个答案:

答案 0 :(得分:0)

HTML

<div id="result"></div>
<div id="result1"></div>
<div class="rrr">
<input type="radio" name="selector_" value="post_active" id="posts">Post
<br>
<input type="radio" name="selector_" value="page_active" id="pages">Page
</div>
<br />
<br />
<div class="rrr">
<input type="radio" name="selector_1" value="post_active1" id="posts1">Post
<br>
<input type="radio" name="selector_1" value="page_active1" id="pages1">Page
</div>

的Javascript

$("input:radio[name=selector_]").click(function () {
    var value = $('input:radio[name=selector_]:checked').val();
    $("#result").html(value + " is checked");
});

$("input:radio[name=selector_1]").click(function () {
    var value = $('input:radio[name=selector_1]:checked').val();
    $("#result1").html(value + " is checked");
});