JavaScript Diable Button


由於網友問了相關的問題,所以便寫了,兩個關於 Diable 按鈕的 JavaScriptScript 方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>What is the JS ?</title>
<script type="text/javascript">
function sendLock_1() {
document.getElementById('sendBtn_1').disabled = true;

setTimeout(function() {
document.getElementById('sendBtn_1').disabled = false;
},500);
}

function sendLock_2() {
val = document.getElementById('sendBtn_2').value;
document.getElementById('sendBtn_2').disabled = true;

wait = temp = 5;
timer = setInterval(function() {
temp = parseInt(temp-1)
document.getElementById('sendBtn_2').value = temp + '秒';
if (temp == 0) {
clearInterval(timer);
document.getElementById('sendBtn_2').disabled = false;
document.getElementById('sendBtn_2').value = val;
}
},wait*100);
}

function clearText() {
document.getElementById('sendText').value = '';
}
</script>
</head>
<body>
<input type="text" value="" name="sendText" id="sendText" />
<input type="button" value="Send 1" name="sendBtn_1" id="sendBtn_1" onclick="sendLock_1(); clearText()" />
<input type="button" value="Send 2" name="sendBtn_1" id="sendBtn_2" onclick="sendLock_2(); clearText()" />
</body>
</html>