<!DOCTYPE html5> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('#form').submit(function(e) { // put your breakpoint here to look at e alert('Which button was clicked?'); }); }); </script> </head> <body> <form id="form"> <input name="text" type="text"><br/> <input name="commit" type="submit" value="Save"/> <input name="commit" type="submit" value="Cancel"/> </form> </body>
我需要知道submit handler方法单击了哪个按钮。使用 $.click 经办人 不会的 $.submit
$.click
$.submit
请尝试以下操作:
$('#form').submit(function(e) { console.log(e.originalEvent.explicitOriginalTarget); });
这只不过是壁虎,所以你应该寻找其他的解决方案。不过,我一个也不知道。
现在,我所知道的所有浏览器都无法做到这一点。