简体   繁体   English

如何通过jQuery调试DOM操作?

[英]How to debug DOM manipulation by jQuery?

I'm working on an website with some dynamic jQuery content. 我正在一个带有一些动态jQuery内容的网站上工作。 If the user pushed a button ("show menu") on the page, an javascript function runs. 如果用户按下页面上的按钮(“显示菜单”),则会运行javascript函数。 Let this function call loadMenu() . 让此函数调用loadMenu()

The loadMenu() function loads a menu (web conent) from server using ajax. loadMenu()函数使用ajax从服务器加载菜单(Web内容)。 Part of this loaded code is javascript/jquery. 此已加载代码的一部分是javascript / jquery。 2 functions of this code make some elements on the page draggable, 2 other functions make some elements on the webpage droppable. 此代码的2个功能使页面上的某些元素可拖动,而其他2个功能使网页上的某些元素可拖放。 These functions are all started at $.ready-Time (if the DOM is ready). 这些功能都是在$ .ready-Time(如果DOM准备就绪)时启动的。 All this works fine. 所有这些都很好。

Now i added an "MenuAlwaysVisible" feature. 现在,我添加了“ MenuAlwaysVisible”功能。 This means: if the web-page is loading and finished ( ready ) the user doesn't need to press the button "show menu", because the javascript loadMenu() now fires automatically, if the page is ready 这意味着:如果网页正在加载并完成( ready ),则用户无需按“显示菜单”按钮,因为如果页面已ready ,则javascript loadMenu()现在会自动触发

The problem now is, it looks like, the draggable handler are attached and worked as defined, but droppable does not work. 现在的问题是,似乎可拖动的处理程序已附加并按定义工作,但是droppable不起作用。

I'm not sure, but probably the droppable function runs on a time, where the DOM elements doesn't like to be droppable? 我不确定,但是droppable函数可能会在DOM元素不喜欢被放置的时间运行? Ore maybe some other jQuery codes overrides this? 也许其他一些jQuery代码会覆盖这个吗? (but there are no other droppable elements on the page)? (但是页面上没有其他可放置元素)?

So the question is: how to analyze that problem: how to debug DOM manipulation, using Windows and Firefox/Firebug or Safari, Chrome .. whatever... 因此,问题是:如何分析该问题:如何使用Windows和Firefox / Firebug或Safari,Chrome浏览器调试DOM操作。

Thank you! 谢谢!

To answer my own question: i did not found any alternatives way than using firebug and console.info() or console.warn() to debug the code. 回答我自己的问题:除了使用firebug和console.info()console.warn()调试代码外,我没有找到其他替代方法。 Thanks @ all for the comments 谢谢@所有人的评论

One debugging trick I have found endlessly useful for dealing with JQuery is the insert obvious code trick. 我发现一种对处理JQuery毫无用处的调试技巧是插入显而易见的代码技巧。 Slap in a .hide() command on some obvious, identifiable part of the page, and see if the code ever runs. 在页面的某些明显的可识别部分上插入.hide()命令,然后查看代码是否曾经运行过。 Lets you track which code pieces are not behaving as intended, and which are simply never being used in the first place. 使您可以跟踪哪些代码段未按预期运行,而哪些代码根本就没有使用过。

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

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