Created
August 4, 2012 17:20
-
-
Save mitsuruog/3258840 to your computer and use it in GitHub Desktop.
To disable if click the button twice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="next.html" name="frm" id="frm"> | |
<input type="text" id="id"/> | |
<input type="submit" id="submit" onClick="return false;"> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
})(); |
間違ってました。
event.returnValue = false;でした。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Submitボタンの2度押しを防止するサンプル