在使用greasemonkey过程中,对angularJS框架的WEB 进行自动表单提交动作。
发现JQuery的对inputd的val()赋值操作会使原有的angularJS的绑定验证操作失效。
虽然我在赋值的同时使用的jQuery的change 和trigger方法都没有效果。
查找stackoverflow上看到一个人的情况与我类似,并且下面的解决办法我经过测试也是没有问题的,完美的解决我的问题。
参照歪果仁的一个解决办法:
- Set the value.
- Send a change event. For Greasemonkey/Tampermonkey scripts you must be mindful of the sandboxes and jQuery conflicts for this part.
Using a jQuery
.change()
- , or
.trigger()
- , from a userscript that is not injected, seldom works. Send a proper change event; see below.
- Since you
@require
- d jQuery (good), but used
@grant none
- The script has a race condition and was often firing before the inputs were ready. Waiting for
window.load
- seems to be enough, but you may have to step up to something like
waitForKeyElements()
- There may be additional timing issues with the
$('#SignupButton').click ();
- DO NOT USE THIS KNOWLEDGE TO VIOLATE ANY WEBSITE'S TERMS OF SERVICE. (If applicable)
With that, the script becomes:
Note that we use a valid @grant
value, other than none
. That's crucial to avoid conflicts with the page's javascript.
参考地址:http://stackoverflow.com/questions/34360739/automate-form-submission-on-an-angularjs-website-using-tampermonkey