所以我使用以下内容来捕获已检查的单选按钮的值,它在Chrome中运行正常,但在Firefox中我只是未定义为活动值。
关于它可能是什么,或者我如何解决它的任何想法?
$("#registerResultsButton").click(function () {
var Competition = $("body").attr("data-competitionId");
var Activity = $('input:radio[name=group1]:checked').val();
console.log(Competition + Activity);
});
HTML看起来像:
<input type="radio" name="group1" value="1101" data-toggle="radio"> meetings taken (5 points)
<label class="radio">
<span class="icons">
<span class="first-icon fui-radio-unchecked"></span>
<span class="second-icon fui-radio-checked"></span>
</span>
<input type="radio" name="group1" value="1111" data-toggle="radio"> closed restaurants (50 points)
</label>
<label class="radio">
<span class="icons">
<span class="first-icon fui-radio-unchecked"></span>
<span class="second-icon fui-radio-checked"></span>
</span>
<input type="radio" name="group1" value="1121" data-toggle="radio"> upsell (100 points)
</label>
</div>
</div>
答案 0 :(得分:0)
应为var Activity = $(':radio[name="group1"]:checked').val();
答案 1 :(得分:0)
问题不在于您的单选按钮,错误是您身体上的数据属性检查是否已定义,因为它表示您的属性未定义
答案 2 :(得分:0)
如果您的活动未定义,请尝试:
var Activity = $('input[type="radio"][name="group1"]:checked').val();
这将检查类型为radio
且名称为group1
的输入,然后检查并获取值。