gpt4 book ai didi

javascript - Rails 4 jquery 高亮效果不执行

转载 作者:行者123 更新时间:2023-11-30 05:35:15 24 4
gpt4 key购买 nike

我试图在我的帖子索引页面中突出显示更改,该页面还显示并提交了表单(都在同一页面上)。我想滑动并突出显示新帖子。要知道 post==new 我是否将 current_item 放入我的 Controller 中:

respond_to do |format|  
if @post.save
format.html { redirect_to posts_path, notice: '<i class="fa fa-check fa-5x"></i>'.html_safe }
format.js { @current_item = @post } #use this in vew to check if post is newly added
format.json { render action: 'index', status: :created, location: @post }

else
format.html { render action: 'new' }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end

index.html.erb:

<% if post == @current_item %>
<div id="current_item">
<% end %>

..........more code......

<% if post == @current_item %>
</div>
<% end %>

我的 js

 $(function() {
$('#current_item').effect('highlight', {}, 3000)
});

没有任何反应,我也在尝试对该 div 进行向下滑动效果,但希望首先使突出显示工作。

我尝试用 css 来做,但没有成功。它突出了一切。

最佳答案

此效果不是核心 jQuery 库的一部分。它是 jQuery UI 库的一部分。你把它包括在你的项目中了吗?来源:api.jqueryui.com/highlight-effect

这是一个工作示例:

$(function() 
{
$('#current_item').effect('highlight', {}, 3000)
});

http://jsfiddle.net/s8ubK/

所以,我猜你忘了在你的项目中包含 jQuery UI 库。

关于javascript - Rails 4 jquery 高亮效果不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24173569/

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