这是影响单选按钮行为的咖啡脚本。示例可以在这里找到:http: //jsfiddle.net/ambiguous/Xk5ZC/
$(document).on 'change', '.stepRadio', ->
$container = $(@).closest('.stepCreator')
$container.find(".excelCreator, .videoCreator, .mcCreator").hide()
if @value is "video"
$container.find(".videoCreator").show()
else if @value is "excel"
$container.find(".excelCreator").show()
else if @value is "multiple_choice"
$container.find(".mcCreator").show()
# This initializes things. Since I have `:checked => true`
# on the first radio button, `:checked` will always match one
# radio button.
$('.stepRadio:checked').change()
这是将上述内容转换为 iCheck 的尝试。但是,我在代码的最后一行遇到问题,我正在尝试初始化咖啡脚本。
$(document).on 'ifChecked', '.stepRadio', ->
$container = $(@).closest('.stepCreator')
$container.find(".excelCreator, .videoCreator, .mcCreator").hide()
if @value is "video"
$container.find(".videoCreator").show()
else if @value is "excel"
$container.find(".excelCreator").show()
else if @value is "multiple_choice"
$container.find(".mcCreator").show()
# This does not initialize things, as it should:
$('.stepRadio:checked').ifChecked()
我还尝试了其他一些方法来初始化代码,例如
$('.stepRadio:checked').iCheck('check')
没有任何效果。
任何帮助,将不胜感激。这里是 icheck:https ://github.com/fronteed/iCheck