我使用rails 4制作网络应用程序。
我的项目视图文件夹中有一个表单,它有嵌套的问题。如果顶级问题的答案为真,则将显示更多子问题。如果答案是错误的,那么与该顶级问题相关的子问题仍然是隐藏的。
我的javascripts文件夹中有一个表单助手,它有该表单的隐藏/显示功能。当我使用Chrome作为浏览器时,它工作正常。它在野生动物园中根本不起作用。在safari中,将显示所有表单元素,包括那些应该在开头隐藏的表单元素。
如何调整表单助手以使其适用于所有浏览器?
在我的JS表单助手文件中,我有:
# source input attrs: {class: 'toggle_div', target: <TARGET_ID_OR_CLASS>}
# toggle_radio attr : {class: 'toggle_div', target: <TARGET_ID_OR_CLASS>, toggle_reverse: <anything> }
#$ ->
# $(document).on 'change', 'input.toggle_div', ()->
# $($(this).attr('target')).toggle this.checked
#
# $(document).on 'change', 'input.toggle_radio', ()->
# reverse = $(this).attr('toggle_reverse')
# if reverse
# toggle_value = ($(this).val() == 'false')
# else
# toggle_value = ($(this).val() == 'true')
# target = $(this).attr('target')
# $(target).toggle toggle_value
#$ ->
$ ->
setTheAttributes = (inString)->
if $('#' + inString + '_sweep_attributes_if_datum').is(':checked')
$('#datarequest').show()
else
$('#datarequest').hide()
$(document).on 'change', '#' + inString + '_sweep_attributes_if_datum', ()->
if $('#' + inString + '_sweep_attributes_if_datum').is(':checked')
$('#datarequest').show()
else
$('#datarequest').hide()
formList = document.getElementsByTagName "form"
if(formList[0].action.includes "/projects")
setTheAttributes 'project'
if(formList[0].action.includes "/programs")
setTheAttributes 'program'
if(formList[0].action.includes "/proposals")
setTheAttributes 'proposal'
在我的application.js文件中,我有:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-switch
//= require_tree .