简体   繁体   English

在Chrome检查器或Firebug中重新运行.js文件?

[英]Rerun .js-File in Chrome inspector or Firebug?

During website development: 网站开发期间:

Before closing the html/body, I include a call to a .js-File, to do some DOM-manipulating via Javascript/jquery (eg $('#foo a').addClass('bar'); etc., the usual). 在关闭html / body之前,我包括对.js文件的调用,以通过Javascript / jquery进行一些DOM操作(例如$('#foo a')。addClass('bar');等,通常)。

I open the file in the browser, then F12-inspect the code and then -- developing -- try out "this and that" by directly manipulating the HTML in the console. 我在浏览器中打开文件,然后F12检查代码,然后通过直接在控制台中操作HTML来进行开发。 Of course, the jquery does not work on those freshly manipulated elements, because it has already been fired and is through. 当然,jquery不适用于那些新操作的元素,因为它已经被触发并通过了。 Is there any way I can tell the Chrome (or the Firebug) inspector to re-run that .js-File just to see how it would work on the changed elements of the HTML-document? 有什么办法可以告诉Chrome(或Firebug)检查器重新运行该.js文件,以查看其如何在HTML文档的更改后的元素上工作?

Thanks in advance... 提前致谢...

Both, Firebug and the Chrome DevTools have a Console panel with a command line in it. Firebug和Chrome DevTools都具有一个带有命令行的“ 控制台”面板。 This command line allows you to execute the same JavaScript for these newly added elements. 此命令行允许您为这些新添加的元素执行相同的JavaScript。

Another approach would be to use jQuery's .on() method for automatic event binding of elements when the HTML structure is changed as described in another answer . 另一种方法是使用jQuery的.on()方法 ,当HTML结构如另一个答案中所述更改时自动进行元素的事件绑定。 This would then eg look like: 然后,例如:

$(document.body).on('change', '#foo a', function() {
    $(this).addClass('bar');
});

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

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