这是影响单选按钮行为的咖啡脚本。可以在此处找到示例: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。但是,我在代码的最后一行遇到了问题,我正试图将coffeescript初始化。
$(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:检查 ')I检查(' 检查')
没有任何效果。
任何帮助将不胜感激。这是icheck:https://github.com/fronteed/iCheck
答案 0 :(得分:0)
我要找的最后一行是:
$('.stepRadio:checked').trigger('ifChecked')