Skip to content

Instantly share code, notes, and snippets.

@mitsuruog
Created August 4, 2012 17:20
Show Gist options
  • Save mitsuruog/3258840 to your computer and use it in GitHub Desktop.
Save mitsuruog/3258840 to your computer and use it in GitHub Desktop.
To disable if click the button twice
<form action="next.html" name="frm" id="frm">
<input type="text" id="id"/>
<input type="submit" id="submit" onClick="return false;">
</form>
<form action="next.html" name="frm" id="frm">
<input type="text" id="id"/>
<input type="submit" id="submit">
</form>
<script type="text/javascript" src="event.js"></script>id
<script type="text/javascript">
var submit = document.getElementById('submit');
LISTENER.addListener(submit, 'click', HANDLER.submit);
</script>
var LISTENER = (function() {
var listener = {};
listener.addListener = function(elem, type, func) {
// IE以外の場合
if (elem.addEventListener) {
elem.addEventListener(type, func, false);
// IEの場合
} else if (elem.attachEvent) {
if (!func.bridge) {
func.bridge = function() {
func.apply(elem);
};
}
elem.attachEvent('on' + type, func.bridge);
}
};
return listener;
})();
var HANDLER = (function() {
var handler = {};
var flg = false;
handler.submit = function(e){
if(flg){
if(typeof e === 'undefined'){
//IE8以前用
event.returnValue = false;
}else{
e.preventDefault();
}
}else{
flg = true;
}
};
return handler;
})();
@mitsuruog
Copy link
Author

Submitボタンの2度押しを防止するサンプル

@mitsuruog
Copy link
Author

間違ってました。
event.returnValue = false;でした。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment