本文介绍了jQuery DOM事件侦听器失败,并显示“未定义$".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据建议在这里,我在Ruby on Rails应用程序中具有以下内联代码:

Following the advice here, I have the following inline code in a Ruby on Rails app:

  document.addEventListener("DOMContentLoaded", function(event) {
    $("select#graph_line_duration").change(function(){
        $("form").submit();
    });
    $("input#graph_duration").hide();
  });

我收到错误$ is not defined.但是,如果我单击一个链接转到该页面,则该代码可以正常工作,因此我的jquery资产正在加载,并且有足够的时间.

I am getting an error $ is not defined. However, if I click on a link to go to the page, then the code works fine, so my jquery assets are loading, given sufficient time.

推荐答案

尝试一下:

document.addEventListener("load", function(event) { ... })

https://developer.mozilla.org/zh-CN/docs/Web/Events/DOMContentLoaded

这篇关于jQuery DOM事件侦听器失败,并显示“未定义$".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:07
查看更多