简体   繁体   English

在Chrome控制台中编辑jquery时,如何重新运行该事件?

[英]When editing jquery in Chrome console, how to re-run that event?

When using Chrome console, I am editing the value of a variable that is set in the document ready event, but obviously this event has already fired and me editing the variable will have no effect. 使用Chrome控制台时,我正在编辑在文档就绪事件中设置的变量的值,但显然此事件已经触发,并且编辑该变量将无效。

Is there a way to re-run this event somehow? 有办法以某种方式重新运行此事件吗?

Either edit your js files and refresh the page, or enter whatever you want to change into the console part of the Chrome Development Tools to see it without having to refresh the page 编辑您的js文件并刷新页面,或者在Chrome开发工具的控制台部分中输入要更改的内容即可查看,而无需刷新页面

For eg $('p').hide(); 例如$('p').hide();

Although you will obviously still need to edit your files to keep this change permanently. 尽管显然您仍然需要编辑文件以永久保留此更改。

I'm not saying this is a good idea, as it's an event which is supposed to fire once when the DOM is ready, but have you tried this? 我并不是说这是一个好主意,因为这是一个事件,当DOM准备就绪时应该触发一次,但是您是否尝试过?

 $().trigger('ready') 

edit 编辑

scratch that - it won't work as jQuery gets rid of the event handler once it has run the first time. 从头开始-jQuery在第一次运行后会摆脱事件处理程序,因此无法使用。

See this question: 看到这个问题:

How to trigger $().ready() in jQuery? 如何在jQuery中触发$()。ready()?

So you'd probably have to rewrite all of your JS to fit into a separate function and then run that function again. 因此,您可能必须重写所有JS以适合单独的函数,然后再次运行该函数。

Having said that, the scope of the variable you are changing would need to be outside of that new function if it is going to retain the value you have changed it to. 话虽如此,要更改的变量的范围要保留更改后的值,就必须在该新函数之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM