简体   繁体   English

当管理员选择批准按钮并单击提交按钮时以及刷新后,如何禁用表行中的按钮?

[英]How to disable button in table rows when admins select approve button and click submit button, and also after refreshing?

I am basically doing an interface where admins are able to approve and reject records by clicking the approve button and reject button on every table row. 我基本上是在做一个界面,管理员可以通过单击每个表行上的批准按钮和拒绝按钮来批准和拒绝记录。 But I have a few criteria : 但是我有一些标准:

After admin click on approve button, followed by the submit button, the reject button should be disabled and kept permanent, even after refresh no changes are allowed in the future. 在管理员单击“批准”按钮之后,再单击“提交”按钮,即使在刷新后将来也不允许更改,应该禁用拒绝按钮并将其保持永久不变。 Which means to say, the table should show approved on that row. 也就是说,表格应在该行显示已批准。 If admin clicks on reject button, the table should state reject on that row. 如果管理员单击拒绝按钮,则该表应在该行上注明拒绝。

What I have done : Each table row has a approve and reject button. 我所做的事情:每个表格行都有一个批准和拒绝按钮。 But the disable function is not working as what I want. 但是禁用功能无法正常工作。 The disable button functions only work for the first row in the table. 禁用按钮功能仅适用于表中的第一行。

My PHP code: 我的PHP代码:

for($x=0; $x<$i; $x++)
{
   echo "<tr>
<td>". $recordid[$x] ."</td>
<td>". $datetime[$x]."</td>
<td>". $recordid[$x] ."</td>

<td>
    <button type= 'button' class='btn btn-success' name='".$selectedradio[x]."' id='accept' onClick='myFunction()'>Approve</button>
</td>

<td>
    <button type= 'button' class='btn btn-danger' name='".$selectedradio[x]."' id='reject' onClick='myFunction()'>Reject</button>
</td>

}

My JS Code: 我的JS代码:

function myFunction(){
   document.getElementByClassName('btn btn-success').setAttribute('disabled',true)
   document.getElementByClassName('btn btn-danger').setAttribute('disabled',true)
}

Rather doing it with id you should use class like this: 宁可使用id来做到这一点,您应该使用这样的类:

       document.getElementByClassName('reject').setAttribute('disabled',true);
       document.getElementByClassName('accept').setAttribute('disabled',true);

Add a class reject and accept in your html.I recommend jquery. 在您的html中添加拒绝类和接受类。我建议使用jquery。

 <script>
 function enableButton2() {
 document.getElementById("button2").disabled = True;
 }
 </script>
 </head>
     <body>
         <input type="button" id="button1" value="button 1" onclick="enableButton2()"  />
         <input type="button" id="button2" value="button 2" />
     </body>
 </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM