0
在我的Rails應用程序中顯示部分div的切換操作僅在刷新頁面時纔有效。如果我點擊一個鏈接到頁面,所有的切換已經打開,不會對點擊做出反應。任何幫助將不勝感激!此外,如果任何人有關於如何用水豚進行測試的提示,那就太好了。jquery只適用於刷新頁面以切換爲rails應用程序
這在我的應用程序/資產/ JavaScript的
$(document).ready(function(){
$(".donation-time").hide()
$(".donation-candidate").on("click", function(event){
$(this).siblings().first().toggle();
$("span", this).toggleClass("glyphicon-chevron-right glyphicon-chevron-down");
})
})
這是我的部分爲所使用的視圖,並且它是是完全開放的,可見的是點擊後看到的一部分,而不是僅僅是.donation候選到頁面。
<div class="donation-candidate">
<h3><span class="glyphicon glyphicon-chevron-right"></span> <%= candidate_issue.name %></h3>
<div style="margin-left: 32px;"><h4><%= candidate_issue.stance %></h4></div>
</div>
<div class="donation-time">
<div style="margin-left: 32px;">
<%= form_for Donation.new, url: donations_path do |f| %>
<%= f.label :amount %>
<%= f.hidden_field :candidate_issue_id, value: candidate_issue.id %>
<%= f.number_field :amount, in: 1.0..2700.0, step: 1.0 %>
<%= f.hidden_field :issue_id, value: candidate_issue.issue_id %>
<%= f.submit "Donate" %>
<% end %>
</div>
</div>
第一次使用jQuery或JavaScript,所以不太確定在哪裏看。如果您有關於如何使用水豚進行測試的提示,那就太好了。我在場景中包含了js:true,並將selenium作爲寶石,但我不知道如何點擊打開div,因爲它顯然不是按鈕或鏈接。謝謝!
默認你在哪裏把'
您使用的是turbolinks嗎?
$(Document).ready()
需要與turbolinks解決方法,如本文所述use document ready with turbopinks來源
2015-09-27 14:53:43 Ethan
是的!謝謝!這樣可行。有關如何使用水豚/硒測試div內容的任何提示?並感謝@湯姆 - 沃波爾(同樣的問題解決了)。 – tinydancer