Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按随机顺序禁用按钮,Rails/javascript_Javascript_Ruby On Rails - Fatal编程技术网

按随机顺序禁用按钮,Rails/javascript

按随机顺序禁用按钮,Rails/javascript,javascript,ruby-on-rails,Javascript,Ruby On Rails,我有一堆按钮,一共3个 这些按钮搞乱了我的头哈,这些按钮以一种奇怪的顺序禁用。如果我按按钮2,它将禁用(因为它向数据库提交数据而禁用)一旦禁用,我可以单击按钮3提交数据,但它不会禁用。然而。按钮一会 其他方法也一样。如果你按按钮3,它将禁用,我可以禁用另外两个。如果我点击按钮一,我不能禁用其他两个,但它很好 在解释这件事时,你会温柔一点吗?我才刚开始学习rails哈哈 这是代码 <div id="a" style="margin-right: 5px; float: left;">

我有一堆按钮,一共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 %>

$('a').html('Disabled');
$('#b').html('Disabled');
$('#c').html('Disabled');
好的

我反复使用If命令修复了这个问题。elsif和其他人似乎把事情搞砸了。因此,只要在Js.erb中将它们全部更改为If并添加
就可以了

山姆

好的

我反复使用If命令修复了这个问题。elsif和其他人似乎把事情搞砸了。因此,只要在Js.erb中将它们全部更改为If并添加
就可以了


Sam

更清楚地解释问题。确保每次单击按钮时,服务器都会给出响应。对不起,我不认为这很难。我需要按任意顺序禁用按钮,而不仅仅是后退。您是否正确地从服务器获得响应?刷新页面后按钮保持禁用状态,但我不希望在单击按钮后刷新。请更清楚地解释问题。确保每次单击按钮时,您收到服务器的响应。很抱歉,我不认为这很难。我需要按钮以任何顺序禁用,而不仅仅是后退。您是否正确地从服务器获得响应?刷新页面后按钮保持禁用状态,但我不希望在单击按钮后刷新