Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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
如何在刷新浏览器后仍在html中禁用按钮_Html - Fatal编程技术网

如何在刷新浏览器后仍在html中禁用按钮

如何在刷新浏览器后仍在html中禁用按钮,html,Html,我使用以下代码创建了两个连接的按钮。一个在另一个禁用时启用,反之亦然。现在的问题是,当我刷新浏览器页面时,按钮将恢复到其原始状态,我希望它们仅在刷新页面时保持当前状态,并且仅在手动按下按钮时才应更改状态。我如何实现这一点 提前谢谢 开始 停止 我有一个想法,通过使用会话cookies,我可以做到这一点,但我不知道如何访问它们 只需使用按钮的disable属性即可 <button onclick="this.disabled=true;document.getElementById

我使用以下代码创建了两个连接的按钮。一个在另一个禁用时启用,反之亦然。现在的问题是,当我刷新浏览器页面时,按钮将恢复到其原始状态,我希望它们仅在刷新页面时保持当前状态,并且仅在手动按下按钮时才应更改状态。我如何实现这一点

提前谢谢

开始
停止


我有一个想法,通过使用会话cookies,我可以做到这一点,但我不知道如何访问它们

只需使用按钮的disable属性即可

<button onclick="this.disabled=true;document.getElementById('start').disabled=false;" type="submit" class="negative" name="stop" id="stop" disabled>Stop</button>   
HTML


希望这有帮助。

您总是在加载时禁用某个按钮。这可能不是OP想要的,他会想禁用刷新前最后一次单击的按钮。@UmairP这并不能解决我的问题,它会在启动时永久禁用一个按钮,就是这样。我需要保留曾经单击过的按钮,而不考虑该按钮。感谢您使用php更新@UmairP im,那么我该如何做呢?我对Ajax一无所知。请查看本地存储:
<button onclick="this.disabled=true;document.getElementById('start').disabled=false;" type="submit" class="negative" name="stop" id="stop" disabled>Stop</button>   
function changeButtonState(id) {
    document.getElementById('start').disabled = false;
    document.getElementById('stop').disabled = false;
    document.getElementById(id).disabled = true;
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            //success
        }
    }
    xmlhttp.open("GET", "saveState.php?button=" + id, true);
    xmlhttp.send();
}
    <?php 
   $id=$ _SESSION[ 'buttonId']; 
   if(strcmp ( $id , "start" )) 
   { 
    <button onclick="changeButtonState('start')" type="submit" class="positive" name="start" id="start">start</button>
    <button onclick="changeButtonState('stop')" type="submit" class="negative" name="stop" id="stop" disabled>Stop</button>
   }
   else
   {
    <button onclick="changeButtonState('start')" type="submit" class="positive" name="start" id="start" disabled>start</button>
    <button onclick="changeButtonState('stop')" type="submit" class="negative" name="stop" id="stop">Stop</button>
   } 
?>
<?php 
   $id=$_GET[ "button"]; 
   $_SESSION[ 'buttonId']=$ id; 
?>