问题
I need to submit a form on a specific page, and it needs to click a radio button before it submits the form.
I got everything working, however when I let GreaseMonkey submit the form the page just returns a white page. As where if I would click Submit manually, it says 'Wait a second please..' and then goes on to another page.
If neccessary I can give you the URL of the form I am talking about.
This is the script I am using:
$(document).ready(function() {
$("input[pmmethod=paypal]").click();
$(".submit-button").click();
});
回答1:
Sounds like a event handler is attached to the button, you could try to simulate a mouse click on it using native JavaScript instead of the jQuery method;
function simulateClick(node) {
var ev = document.createEvent("MouseEvents");
ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
return node.dispatchEvent(ev);
}
$(document).ready(function() {
$("input[pmmethod=paypal]").click();
simulateClick( $(".submit-button")[0] );
});
回答2:
I know whay tou want...
I've altered the original script and now it will work!
http://userscripts.org/scripts/show/153026
回答3:
To submit a form using JavaScript, use submit() like this:
$(document).ready(function() {
$("input[pmmethod=paypal]").click();
$("#orderform").submit();
});
来源:https://stackoverflow.com/questions/13409322/trying-to-submit-a-form-with-greasemonkey-but-the-page-stops-working