Jquery - Simulating click button doesn't trigger function

大城市里の小女人 提交于 2019-12-23 19:24:30

问题


Ok,

So I have been using firebug and also some extensions I wrote to create shortcuts on website I use often. There's on thing that I don't understand why it doesn't work or why it's not possible:

Example code:

<input type="button" onclick="addNewRow()" id="addRow"/>
//This will add a new row to the current table.
//The function is defined by the website (not my function)

When using firebug:

jQuery("#addRow").click();
//This will simulate the button click, and will automatically add the new row.

When using google chrome extension:

jQuery("#addRow").click();
//It doesn't add the new row.

Why can't the extension execute the function once the button click occurs, and why firebug has no issues in running it?

Is this normal? Is this a security feature? or am I doing something wrong?

I know that I can't access existing functions in a website for security reasons, but why won't the button simulation trigger it for me?


回答1:


Try:

jQuery("#addRow").trigger("click");



回答2:


What version of Chrome are you using ? There is a new Chrome Extensions security feature that blocks inline javascript. You can read more here : http://browserfame.com/512/chrome-extension-content-security-policy




回答3:


On chrome, I would rather use WebKit's developer console rather than firebug extention.



来源:https://stackoverflow.com/questions/9620449/jquery-simulating-click-button-doesnt-trigger-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!