我正在尝试根据单击的按钮隐藏/显示一些 div。每次我单击不同的按钮来显示某个 div 时,它都会跳转到页面顶部。如果相关的话,我也在使用 Ruby on Rails。我也尝试过使用 return false ,但这也不起作用。有人有想法么?谢谢。
Javascript:
$(document).ready(function(){
$('#new-event-button').click(function(e){
e.preventDefault();
$('#edit-events').hide();
$('#delete-events').hide();
$('#new-event').slideDown();
});
$('#edit-events-button').click(function(e){
e.preventDefault();
$('#new-event').hide();
$('#delete-events').hide();
$('#edit-events').slideDown();
});
$('#delete-events-button').click(function(e){
e.preventDefault();
$('#new-event').hide();
$('#edit-events').hide();
$('#delete-events').slideDown();
});
});
查看代码:
<button id="new-event-button">New Event</button>
<button id="edit-events-button">Edit Events</button>
<button id="delete-events-button">Delete Events</button>
<div id="events-forms">
<div id="new-event">
<%= render :partial => "new_event", :locals => { :event => Event.new(:timeline_id=>@timeline.id) } %>
</div>
<div id="edit-events">
<%= render :partial => "edit_events", :locals => { :events => current_user.events } %>
</div>
<div id="delete-events">
<%= render :partial => "delete_events", :locals => { :events => current_user.events } %>
</div>
</div>