如何在JSP中单击按钮后永久禁用按钮。

huangapple go评论110阅读模式
英文:

how to disable a button permanently after clicking it in jsp

问题

如何在单击按钮后永久禁用它?即使在刷新页面后它仍然应该保持禁用状态。但是在刷新页面后,按钮又变为启用状态。如何做到这一点?

英文:

how to disable a button permanently after clicking it ?it should remain disabled after refreshing the page also.But after refreshing the page the button is enabled again.how to do this??

答案1

得分: 1

以下是您要求的翻译内容:

其实非常简单,只需将 disabled 属性更改为 true。

<script type="text/javascript">
    function disableButton(btn){
        document.getElementById(btn.id).disabled = true;
        alert("按钮已被禁用。");
    }
</script>

使用 HTML,它看起来会是这样的:

<!--JavaScript - 在点击后使用 JavaScript 函数禁用按钮。-->
<html>
    <head>
        <title>JavaScript - 在点击后使用 JavaScript 函数禁用按钮。</title>
        <script type="text/javascript">
            function disableButton(btn){
                document.getElementById(btn.id).disabled = true;
                alert("按钮已被禁用。");
            }
        </script>
    </head>

    <body style="text-align: center;">
        <h1>JavaScript - 在点击后使用 JavaScript 函数禁用按钮。</h1>
        <p><input type="button" id="btn1" value="点击以禁用按钮。" onclick="disableButton(this)"></p>

    </body>

</html>
英文:

its really easy , just change disabled property to true..

 &lt;script type=&quot;text/javascript&quot;&gt;
    	function disableButton(btn){
    		document.getElementById(btn.id).disabled = true;
    		alert(&quot;Button has been disabled.&quot;);
    	}
    &lt;/script&gt;

with HTML it would look smth like this

&lt;!--JavaScript - Disable Button after Click using JavaScript Function.--&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;JavaScript - Disable Button after Click using JavaScript Function.&lt;/title&gt;
		&lt;script type=&quot;text/javascript&quot;&gt;
			function disableButton(btn){
				document.getElementById(btn.id).disabled = true;
				alert(&quot;Button has been disabled.&quot;);
			}
		&lt;/script&gt;
	&lt;/head&gt;

	&lt;body style=&quot;text-align: center;&quot;&gt;
		&lt;h1&gt;JavaScript - Disable Button after Click using JavaScript Function.&lt;/h1&gt;
		&lt;p&gt;&lt;input type=&quot;button&quot; id=&quot;btn1&quot; value=&quot;Click to disable button.&quot; onclick=&quot;disableButton(this)&quot;&lt;/p&gt;

	&lt;/body&gt;

&lt;/html&gt;

huangapple
  • 本文由 发表于 2020年8月24日 19:43:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63560362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定