[英]Buttons disabling in a random order, Rails/javascript
我有一堆按鈕,總共3個。
這些按鈕弄亂了我的腦袋,這些按鈕以奇怪的順序被禁用。 如果我按按鈕2,它將被禁用(它被禁用,因為它正在向數據庫提交數據)一旦被禁用,我可以單擊按鈕3來提交數據,但它不會被禁用。 然而。 一按就好。
其他方法也一樣。 如果按按鈕3,它將禁用,我可以禁用其他兩個。 如果我單擊一個按鈕,則無法禁用其他兩個按鈕,但是數據提交正常。
在解釋這一點時,您會很溫柔嗎? 我才剛開始使用rails哈哈!
這是代碼;
<div id="a" style="margin-right: 5px; float: left;">
<% if @conference_status.cross_charged_user_id.present? %>
<button id="a" class="btn btn-primary" disabled="disabled">Disabled</button>
<% else %>
<%= link_to 'Cross charged to Client', admin_conference_status_path(@conference_status, status_name: 'cross_charged_use'), class: "btn btn-primary", method: :put, remote: true, prompt: 'Are you sure?' %>
<% end %>
</div>
<div id="b" style="margin-right: 5px; float: left;">
<% if @conference_status.payment_received_comm_user_id.present? %>
<button class="btn btn-primary" disabled="disabled">Disabled</button>
<% else %>
<%= link_to 'Payment received Commission', admin_conference_status_path(@conference_status, status_name: 'payment_received_comm'), class: "btn btn-primary", method: :put, remote: true %>
<% end %>
</div>
<div id="c" style="margin-right: 5px; float: left;">
<% if @conference_status.payment_received_client_user_id.present? %>
<button class="btn btn-primary" disabled="disabled">Disabled</button>
<% else %>
<%= link_to 'Payment Received', admin_conference_status_path(@conference_status, status_name: 'payment_received'), class: "btn btn-primary", method: :put, remote: true %>
<% end %>
</div>
這是js.erb
<% if @conference_status.cross_charged_datetime.present? %>
$('#a').html('<button class="btn btn-primary" disabled="disabled">Disabled</button>');
<% elsif @conference_status.payment_received_comm_user_id.present? %>
$('#b').html('<button class="btn btn-primary" disabled="disabled">Disabled</button>');
<% else @conference_status.payment_received_client_datetime.present? %>
$('#c').html('<button class="btn btn-primary" disabled="disabled">Disabled</button>');
<% end %>
好的,
我反復使用If命令解決了這個問題。 Elsif和其他人似乎搞砸了。 因此,只需在Js.erb中將它們全部更改為If並添加<% end %>
正常工作
山姆
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.