Chrome javascript 调试器断点不执行任何操作?

编程入门 行业动态 更新时间:2024-10-20 09:27:06
本文介绍了Chrome javascript 调试器断点不执行任何操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我似乎无法弄清楚 Chrome 调试工具.

I can't seem to figure out the Chrome debugging tool.

我有 21.0.1180.60 m 的 chrome 版本.

I have chrome version 21.0.1180.60 m.

我采取的步骤:

  • 我按下了 ctrl-shift-i 以调出控制台.
  • 点击 Sources,然后选择我想要调试的相关 javascript 文件.
  • 我通过在左侧行旁边的装订线中放置一个蓝色标签来设置我希望代码停止的断点.
  • 我点击了我的网页(这是一个 php 呈现的页面)上启动 javascript 代码的按钮.
  • 代码成功运行,没有停止.
  • 我还注意到监视表达式也不起作用.它一直告诉我我想观察的变量未定义.

    I also noticed that the Watch Expressions don't work either. It keeps telling me that the variable that I want to watch is undefined.

    进一步测试发现是我的代码导致断点失败.似乎它在 "$("#frmVerification").submit(function(){" 行上失败了.它没有进入那个 function() 内的断点.

    Further testing found that it's my code that's causing the breakpoint to fail. It seems that it fails on the "$("#frmVerification").submit(function(){" line. It doesn't step into the breakpoints inside that function().

    以下是:

    //function to check name and comment field var test = "this is a test"; var test2 = "this is another test"; function validateLogin(){ //if(userEmail.attr("value") && userPass.attr("value")) return true; //else //return false; } //onclick on different buttons, do different things. function ajaxRequest(){ } $(document).ready(function(){ //When form submitted $("#frmVerification").submit(function(){ var username = $("#username"); var token = $("#token"); var action = $("#action"); var requester = $("#requester"); if(validateLogin()){ $.ajax({ type: "post", url: "verification.php", data: "username="+username.html()+"&token="+token.val()+"&action="+action.val()+"&requester="+requester.val(), success: function(data) { try{ var jsonObj = $.parseJSON(data); //convert data into json object, throws exception if data is not json compatible if(jsonObj.length > 0){//if there is any error output all data var htmUl = $('<ul></ul>'); $.each(jsonObj, function(){ htmUl.append('<li>' + this + '</li>'); }); $("#errOut").html(htmUl); }else{ alert("Your account is now activated, thank you. If you have already logged in, press OK to go to the home page. If not, you must log in first."); window.location.replace("home.php"); } } catch(e){//if error output error to errOut] $("#errOut").html("PHP module returned non JSON object: <p>"+data+"</p>"); } } }); } else alert("Please fill UserName & Password!"); return false; }); });

    推荐答案

    我不知道为什么你的断点没有命中,但是进入你的代码的一种可靠方法是输入

    I'm not sure why your breakpoints aren't hitting, but one sure-fire way to step into your code is to type

    debugger;

    您希望代码在何处停止,然后在 chrome 开发人员工具窗口打开的情况下再次运行.

    where you want the code to halt, and then run again with the chrome developer tools window open.

    只需要注意一件小事,完成后一定要清理并删除调试器行.如果您曾经通过 YUI 压缩器运行 JavaScript 文件,debugger; 行的存在将导致它出错.

    Just one small thing to be aware of, be sure to clean up after you done and remove the debugger lines. If you ever run JavaScript files through YUI compressor, the existence of a debugger; line will cause it to error out.

    更多推荐

    Chrome javascript 调试器断点不执行任何操作?

    本文发布于:2023-11-28 16:37:28,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1643159.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:断点   操作   调试器   Chrome   javascript

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!