js 控制按鈕點擊后不可用


  為了防止用戶多次點擊某按鈕,造成多次提交表單的操作。某些按鈕需要在點擊后實現不可用操作。

  例子:

<html>
<head>
<title>同意條款</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="submit" name="Submit" value="同意" />
</form>
<script language="javascript">
document.form1.Submit.disabled = true;
var wait = 9; //停留時間
function updateinfo(){
  if(wait == 0){
    document.form1.Submit.value = "我同意";
    document.form1.Submit.disabled = false;
  }
  else{
    document.form1.Submit.value = "閱讀條款"+wait;
    wait--;
    window.setTimeout("updateinfo()",1000);
  }
}
updateinfo();
</script>
</body>
</html>

 

  設置按鈕的不可用 用到了 disabled屬性。

  語法:

 

object.disabled = false | true;

  例子:w3cschool

<html>
<head>
<script type="text/javascript">
function disable()
  {
  document.getElementById('txt1').disabled=true;
  }
function enable()
  {
  document.getElementById('txt1').disabled=false;
  }
</script>
</head>
<body>

<textarea id="txt1">
Hello world....This is a text area
</textarea>
<br />
<input type="button" onclick="disable()" value="Disable" />
<input type="button" onclick="enable()" value="Enable" />

</body>
</html>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM