BootstrapSwitch无法正常工作

时间:2014-04-21 16:09:55

标签: twitter-bootstrap twitter-bootstrap-3

我有一个简单的Yes No开关没有显示。它显示为一个复选框。

<%= f.label :correct, "Correct Answer?" %><br>
<%= f.check_box :correct %>

<script>
$(document).ready(function(){
    $("#answer_correct").bootstrapSwitch('onText', 'Yes');
    $("#answer_correct").bootstrapSwitch('offText', 'No');
    $("#answer_correct").bootstrapSwitch('size', 'large');
});
</script>

这是控制台信息:

<input id="question_answers_attributes_0_correct" name="question[answers_attributes][0][correct]" type="checkbox" value="1">

我错过了什么吗?谢谢

1 个答案:

答案 0 :(得分:1)

JQuery ID选择器没有引用页面上输入元素的那个。

$("#answer_correct")更改为:

$("#question_answers_attributes_0_correct")选择正确的ID

$("[name='question[answers_attributes][0][correct]']")按名称选择元素。

相关问题