<html>
<head>
<meta charset="utf-8">
<title>ストップウォッチ</title>
</head>
<body>
<div id="clock">00:00:00</div>
<form>
<input type="button" id="start" value="Start">
<input type="button" id="stop" value="Stop" disabled>
<input type="button" id="restart" value="Restart" disabled>
<input type="button" id="reset" value="Reset" disabled>
<script src="https://code.jquery.com/jquery-2.0.3.js"></script>
</form>
</body>
</html>
$(function () {
var sec = 0;
var min = 0;
var hour = 0;
var timer;
// スタート
$('#start').click(function() {
// 00:00:00から開始
sec = 0;
min = 0;
hour = 0;
$('#clock').html('00:00:00');
timer = setInterval(countup, 1);
$(this).prop('disabled', true);
$('#stop,#reset').prop('disabled', false);
});
// ストップ
$('#stop').click(function() {
// 一時停止
clearInterval(timer);
$(this).prop('disabled', true);
$('#restart').prop('disabled', false);
});
// リスタート
$('#restart').click(function() {
// 一時停止から再開
timer = setInterval(countup, 1000);
$(this).prop('disabled', true);
$('#stop').prop('disabled', false);
});
// リセット
$('#reset').click(function() {
// 初期状態
sec = 0;
min = 0;
hour = 0;
$('#clock').html('00:00:00');
clearInterval(timer);
$('#stop,#restart,#reset').prop('disabled', true);
$('#start').prop('disabled', false);
});
/**
* カウントアップ
*/
function countup()
{
sec += 1;
if (sec > 59) {
sec = 0;
min += 1;
}
if (min > 59) {
min = 0;
hour += 1;
}
// 0埋め
sec_number = ('0' + sec).slice(-2);
min_number = ('0' + min).slice(-2);
hour_number = ('0' + hour).slice(-2);
$('#clock').html(hour_number + ':' + min_number + ':' + sec_number);
}
});
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |