Chrome javascript调试器断点不';我什么也不做?
我似乎搞不懂Chrome的调试工具 我有chrome版本21.0.1180.60 m 我采取的步骤:Chrome javascript调试器断点不';我什么也不做?,javascript,debugging,google-chrome,Javascript,Debugging,Google Chrome,我似乎搞不懂Chrome的调试工具 我有chrome版本21.0.1180.60 m 我采取的步骤: 我按ctrl-shift-I打开控制台 单击Sources,然后选择要调试的相关javascript文件 我通过在左侧行旁边的边沟上放置一个蓝色标记,在希望代码停止的位置设置断点 我点击了我的网页上的按钮(这是一个php呈现的页面),启动javascript代码 代码没有停止就成功运行了 我还注意到手表的表情也不起作用。它一直告诉我,我想要观察的变量是未定义的 进一步的测试发现是我的代码导致断点
//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;
});
});
//检查名称和注释字段的函数
var test=“这是一个测试”;
var test2=“这是另一个测试”;
函数validateLogin(){
//if(userEmail.attr(“值”)和&userPass.attr(“值”))
返回true;
//否则
//返回false;
}
//点击不同的按钮,做不同的事情。
函数ajaxRequest(){
}
$(文档).ready(函数(){
//提交表格时
$(“#frmVerification”).submit(函数(){
变量用户名=$(“#用户名”);
变量标记=$(“#标记”);
var action=$(“#action”);
变量请求者=$(“#请求者”);
if(validateLogin()){
$.ajax({
类型:“post”,
url:“verification.php”,
数据:“username=“+username.html()+”&token=“+token.val()+”&action=“+action.val()+”&requester=“+requester.val()”,
成功:功能(数据){
试一试{
var jsonObj=$.parseJSON(data);//将数据转换为json对象,如果数据与json不兼容,则引发异常
如果(jsonObj.length>0){//如果有任何错误,请输出所有数据
var htmUl=$(“
”);
$.each(jsonObj,function(){
htmUl.append(''+this+' ');
});
$(“#errOut”).html(htmUl);
}否则{
警报(“您的帐户现在已激活,谢谢。如果您已经登录,请按“确定”转到主页。如果没有,则必须先登录。”);
window.location.replace(“home.php”);
}
}
catch(e){//if error输出error到errOut]
$(“#errOut”).html(“PHP模块返回的非JSON对象:”+data+“”);
}
}
});
}
else警报(“请填写用户名和密码!”);
返回false;
});
});
我不知道为什么断点没有命中,但一个可靠的方法是键入
debugger;
您希望代码停止,然后在chrome developer tools窗口打开的情况下再次运行
需要注意的一点是,在完成并删除调试器行之后,请务必进行清理。如果您曾经通过YUI compressor运行JavaScript文件,则
调试器;
行的存在将导致其出错。因此,除了Adam Rackis的回答之外,如果您的JavaScript文件中存在断点以上的错误,则无论您是否标记它或将其放入调试器;
,都无法访问它
下面是一个例子:
if (nonExistentVar === "something") {
console.log("this won't happen as the above errors out");
}
debugger;
console.log("this won't print either")
可能是这个虫子
这是我的Chrome 31.0.1650.57(官方版本235101)在Linux上复制的
我正在重新启动浏览器进行修复。我在chrome和firefox中都遇到了类似的问题,尽管这可能不是解决您问题的方法。我在这里分享,希望它能帮助其他人。我以前在其他不相关的项目中也遇到过这种情况,但直到今天它再次出现,我才明白原因 场景: 我有一个页面使用了来自同一个源的两个引导模式和一组javascript文件(blueimp很棒的jquery文件上传)
- BS Modal 1在页面加载时呈现(通过php),并始终显示在页面上。它用于添加新的相关记录。(CakePHP…想想SalesForcey类型的东西)
- BS Modal 2用于编辑现有的相关记录,它的html内容从ajax调用中拉入,并通过jQuery附加到DOM中
- Javascript通过标准html
标记支持这两种模式
PS:我一直在使用SO,但这是我的第一篇帖子,所以请对我放松:-)确保您在URL中使用的主机与设置映射时使用的主机相同。例如,如果您位于
http://127.0.0.1/my-app
设置并映射工作区时,如果通过http://localhost/my-app
。
另外,感谢您阅读本文。请参阅我对chrome问题的回答。确保您已在chrome窗口中打开javascript控制台(或源代码)。否则它将永远不会到达断点。
您可以通过右上角-->工具-->javascript控制台中的选项按钮打开javascript控制台。我遇到了类似的问题。除非我使用
调试器;
.I,否则断点不起作用
//@ sourceURL=/Scripts/test.js
//@ sourceURL=/Scripts/test.js
debugger
let myDebuggerFlag = false;
let myDebugger = function () {
if (myDebuggerFlag) {
debugger;
}
}
<script src="ab.js" ></script>
<script src="ab.js" type="text/javascript"></script>
myObject = (function($){
function publicFunction() {}
function privateFunction() {}
return {
theOnlyMethod: publicFunction
}
})(jQuery);