Created
May 22, 2011 17:41
-
-
Save yuanchuan/985699 to your computer and use it in GitHub Desktop.
jQuery live('submit') and disabled submit button
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>jQuery live('submit') and disabled submit button </title> | |
<style> | |
form {margin-bottom:50px;} | |
</style> | |
</head> | |
<body> | |
<form method="post" action=""> | |
<fieldset> | |
<legend>只有一个文本框,点击提交不会提交,但按下 enter 键会提交</legend> | |
<p><input type="text" /></p> | |
<p><input type="submit" value="提交" /></p> | |
</fieldset> | |
</form> | |
<form method="post" action=""> | |
<fieldset> | |
<legend>多于一个文本框,点击或按enter键均不会提交</legend> | |
<p><input type="text" /></p> | |
<p><input type="text" /></p> | |
<p><input type="submit" value="提交" /></p> | |
</fieldset> | |
</form> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> | |
<script> | |
$(function(){ | |
/** | |
* Got problem in IE<9 | |
*/ | |
$('form').live('submit', function(){ | |
$(this).find('input[type="submit"]').attr('disabled', true); | |
}); | |
/** | |
* But both of the two bellow will work fine: | |
* | |
* $('form').submit(function(){ | |
* $(this).find('input[type="submit"]').attr('disabled', true); | |
* }); | |
* | |
* $('form').live('submit', function(){ | |
* $(this).find('input[type="submit"]').attr('title', 'click me'); | |
* }); | |
*/ | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trick to make it work