基本上,我有一个用于b_page的显示页面,并且已经在内部渲染了一个新的局部页面(用于page_posts),并且仅在刷新页面或从浏览器直接打开链接时,该页面的“提交”按钮才起作用。我已经检查过,并且没有丢失的div或未打开的标签等,因此这不是HTML问题。

也许是Turbolinks问题,原因是几乎所有应用程序都发生了这种情况,如果是的话,这是我的application.js.erb

// 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 any plugin's vendor/assets/javascripts directory 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/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery.ui.all
//= require jquery.turbolinks
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-tagsinput
//= require sync
//= require masonry/jquery.masonry
//= require jscolor
//= require_tree .
//= require owl.carousel
//= require turbolinks


我怎样才能解决这个问题?这是show.html.erb的链接。

最佳答案

您必须使用$(document).on('ready', function(){})

将其更改为$(document).on('turbolinks:load', function (){}),这将强制在查看页面时加载JavaScript。

关于javascript - Ruby on Rails提交按钮仅在刷新时有效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46243966/

10-12 05:15