我在 chrome 扩展中有简单的内容脚本来捕获所有表单提交。它在按钮触发提交时起作用(参见代码),但在 jquery 调用时不起作用。它应该工作无法理解出了什么问题。
content.js
---------
jQuery("form").submit(function() {
alert('submit hooked!: ' + $(this).serialize());
});
页:
page.html
--------
<html>
<head>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script language="JavaScript">
function foo() {
jQuery("#some_form").submit();
}
function foo_native() {
document.getElementById('some_form').submit();
}
</script>
</head>
<body>
<form action="http://example.com/handler" id="some_form">
Your name:<input type="text" name="name"><br>
Your email:<input type="text" name="email"><br>
<!-- This hooked -->
<input type="submit" value="Send simple submit"><br>
<!-- Hook not working for such calls -->
<input type="button" value="Send jquery submit" onclick="foo()"><br>
<input type="button" value="Send native submit" onclick="foo_native()">
</form>
<br>
</body>
</html>