如何调试为什么此点击处理程序永远不会触发?

发布于 2024-08-27 19:49:58 字数 756 浏览 11 评论 0原文

我将在这里进行极其详细的说明。我在 Max OSX 上使用 Firefox 3.6.3 和 Firebug 1.5.3。

我有一个项目的两个版本,一个可以工作,另一个有错误。一份是我下载的,一份是我手写的。猜猜哪一个不起作用。它们应该是相同的,只是我的使用了较新版本的 jQuery 并且文件的命名不同。 jQuery 版本不是问题。我让我的使用旧的jquery,我让工作的使用新的jquery。不管怎样,我的仍然坏了,下载的仍然有效。我睁大了眼睛试图看看这些项目有何不同。我唯一不想做的就是将工作代码复制到损坏的代码中,因为当我自己的独特代码导致类似问题时,我需要能够弄清楚这些内容。

我在代码中的 Firebug 中没有看到任何错误,事实上,其中 2/3 工作得很好。只是第二个按钮没有任何作用。所以我想跨过去。这些都是眼球错误,我真的很讨厌看到它们。

我把它放在公共服务器上。 http://colleenweb.com/jqtests/ex71.html 我想调试 ex71。 。

如果您对正在运行的程序进行 firebug 并在 ex71.js 中的第 13 行设置断点,则当您单击第二个按钮时,变量 json 具有预期值 但如果你对这个进行firebug,它永远不会到达那里。我已经浏览了 html,所有内容的名称似乎都匹配。我还想知道为什么按钮不右对齐,但这是一个 css 的问题。请告诉我我缺少什么,更重要的是,我可以使用什么工具/技术来查找这些类型的错误。

I am going to be excrutiatingly detailed here. I am using Firefox 3.6.3 on Max OSX with Firebug 1.5.3.

I have two versions of a project, one which works and one with a bug. One I downloaded and one I typed by hand. Take a guess which one doesn't work. They should be the same except that mine uses a newer version of jQuery and the files are named differently. jQuery version is not the issue. I made mine use the older jquery and I made the working one use the newer jquery. Either way, mine still broke and the downloaded one still works. I've busted my eyes trying to see how these projects are different. The only thing I don't want to do is copy the working code to the busted code because I need to be able to figure this stuff out when it is my own unique code causing similar issues.

There are no errors that I can see in Firebug in my code, in fact, 2/3 of it works just fine. just the second button does nothing. So I wanted to step through. These are always eyeball errors and I really suck at seeing them.

I put it on a public server. http://colleenweb.com/jqtests/ex71.html And I want to debug ex71.js

If you firebug the working one and set a break point at line 13 in ex71.js the variable json has the expected values when you click on the second button. But If you firebug this one, it never gets there. I've been over the html and all the names of everything seem to match up. I also wonder why the buttons aren't right justified but that's a css thing. Please tell me what I'm missing, and more importantly, what tool/technique I could use to find these types of bugs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

翻身的咸鱼 2024-09-03 19:49:58

来自 api.jquery:

例如,所有以 JSON 表示的字符串,无论是属性还是值,都必须用双引号引起来。有关 JSON 格式的详细信息,请参阅 http://json.org/。

您确定传入的数据在语法上准确吗?

From api.jquery:

For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes. For details on the JSON format, see http://json.org/.

Are you sure the incoming data is syntactically accurate?

旧梦荧光笔 2024-09-03 19:49:58

我认为您正在使用的函数需要 JSONP。这就是回调=?无论如何都表明。你试过把它关掉吗?

$.getJSON('ex71.json', function(json) {
    $('input#tmpTitle').val(json.title);
    $('input#tmpCompany').val(json.company);
}); 

文档的此页面在注释中解释了回调=?可用于跨域调用所需的JSONP。如果您不进行跨域调用,则不需要它。如果您正在进行跨域调用,那么您需要返回 JSONP 而不是常规 JSON(这实际上比听起来容易得多)。

http://api.jquery.com/jQuery.getJSON/

I think the function you're using is expecting JSONP. That's what the callback=? indicates anyway. Have you tried leaving it off?

$.getJSON('ex71.json', function(json) {
    $('input#tmpTitle').val(json.title);
    $('input#tmpCompany').val(json.company);
}); 

This page on the documentation explains in a note partway down that the callback=? can be used for JSONP which is needed for cross domain calls. If you're not doing a cross domain call then you don't need it. If you are doing a cross domain call then you need to return JSONP instead of regular JSON (which is actually a lot easier than it sounds).

http://api.jquery.com/jQuery.getJSON/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文