gpt4 book ai didi

JavaScript 在 Rails 中不工作

转载 作者:太空宇宙 更新时间:2023-11-03 16:22:05 24 4
gpt4 key购买 nike

JavaScript 无法在 ruby​​ on rails 中运行。我已将我的 JavaScript 包含在 Assets 文件和带有 //=require_tree 的 application.js 中。

我尝试运行的 javascript 代码:$(文档).ready(函数(){

$('#nav > div').hover(
function () {
var $this = $(this);
$this.find('img').stop().animate({
'width' :'199px',
'height' :'199px',
'top' :'-25px',
'left' :'-25px',
'opacity' :'1.0'
},500,'easeOutBack',function(){
$(this).parent().find('ul').fadeIn(700);
});

$this.find('a:first,h2').addClass('active');
},
function () {
var $this = $(this);
$this.find('ul').fadeOut(500);
$this.find('img').stop().animate({
'width' :'52px',
'height' :'52px',
'top' :'0px',
'left' :'0px',
'opacity' :'0.1'
},5000,'easeOutBack');

$this.find('a:first,h2').removeClass('active');
}
);

});

最佳答案

确保在文档准备好后执行 javascript,如下所示(假设您使用的是 JQuery 和 Coffeescript):

$ -> # do you have this?
alert 'test'

同时检查浏览器的控制台是否有任何错误。

更新

尝试用这个替换你的代码,看看显示了哪些警报......

$(document).ready(function() {
alert(1)

$('body').hover(
function () {
alert(2)
}
)

$('#nav > div').hover(
function () {
alert(3)
}
)
})

关于JavaScript 在 Rails 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31902680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com