-3

以下 Javascript 在我的 Visual Studio 中的 aspx.cs 中,我已经添加了一个新脚本,但我不确定我的脚本是否正常工作..所以有人可以告诉我如何调试以下代码……

  sb.AppendFormat("function chkQuoteBinderValidUntilDateOverridden_OnClick()", this.chkQuoteBinderValidUntilDateOverridden.ClientID);
            sb.AppendLine("{");
            sb.AppendLine("    var chkQuoteBinderValidUntilDateOverridden = document.getElementById('" + chkQuoteBinderValidUntilDateOverridden.ClientID + "');");
            sb.AppendLine("    var wdcQuoteBinderValidUntilDate = document.getElementById('" + wdcQuoteBinderValidUntilDate.ClientID + "');");
            sb.AppendLine("    var wdcQuoteBinderValidUntilDate_input = document.getElementById('" + wdcQuoteBinderValidUntilDate.ClientID + "_input');");
            sb.AppendLine("    var wdcQuoteBinderValidUntilDate_container = document.getElementById('" + wdcQuoteBinderValidUntilDate.ClientID + "_container');");
            sb.AppendLine("    var wdcQuoteBinderValidUntilDate_img = document.getElementById('" + wdcQuoteBinderValidUntilDate.ClientID + "_img');");
            sb.AppendLine("    var wdcQBValidUntilDate = igdrp_getComboById('" + this.wdcQuoteBinderValidUntilDate.ClientID + "');");
            sb.AppendLine("    var hiddenWDCQBValidUntilDate = document.getElementById('" + this.HiddenWDCQuoteBinderValidUntilDate.ClientID + "');");
            sb.AppendLine("    var hiddenQBValidUntilDate = new Date(hiddenWDCQBValidUntilDate.value);");
            sb.AppendLine("    if(chkQuoteBinderValidUntilDateOverridden.checked == true) {");
            sb.AppendLine("        setDateChooserDisabled(wdcQuoteBinderValidUntilDate,false);");
            sb.AppendLine("        wdcQuoteBinderValidUntilDate_img.setAttribute('src', wdcEnabledImageUrl);");
            sb.AppendLine("    }");
            sb.AppendLine("    else {");
            sb.AppendLine("    var now = new Date();");
            sb.AppendLine("        setDateChooserDisabled(wdcQuoteBinderValidUntilDate,true);");
            sb.AppendLine("        wdcQuoteBinderValidUntilDate_img.setAttribute('src', wdcDisabledImageUrl);");
            sb.AppendLine("        if(hiddenQBValidUntilDate) {");            
            sb.AppendLine("             wdcQBValidUntilDate.setValue(hiddenQBValidUntilDate);");
            sb.AppendLine("             if (lblQuoteBinderExpiresIn == null) {");
            sb.AppendLine("                     lblQuoteBinderExpiresIn = document.getElementById('" + lblQuoteBinderExpiresIn.ClientID + "');");
            sb.AppendLine("             }");
            sb.AppendLine("             dif = ((hiddenQBValidUntilDate - now)/(86400*1000));");
            sb.AppendLine("             dif = (dif - ( dif % 1 )) + 1;");
            sb.AppendLine("             lblQuoteBinderExpiresIn.innerText = '(' + dif.toString() + ' days)';");
            sb.AppendLine("         }");
            sb.AppendLine("    }");
            sb.AppendLine("}");

            sb.AppendLine("function wdcQuoteBinderValidUntilDate_OnBlur(oDateChooser , dummy, oEvent) {");
            sb.AppendLine("    var now = new Date();");
            sb.AppendLine("    var wdcQuoteBinderValidUntilDate = oDateChooser.getValue();");                       
            sb.AppendLine("    if (lblQuoteBinderExpiresIn == null) {");
            sb.AppendLine("    lblQuoteBinderExpiresIn = document.getElementById('" + lblQuoteBinderExpiresIn.ClientID + "');");
            sb.AppendLine("    }");
            sb.AppendLine("    if(wdcQuoteBinderValidUntilDate != null)  {"); 
            sb.AppendLine("         dif = ((wdcQuoteBinderValidUntilDate - now)/(86400*1000));");
            sb.AppendLine("         dif = (dif - ( dif % 1 )) + 1;");
            sb.AppendLine("         lblQuoteBinderExpiresIn.style.visibility = 'visible';");
            sb.AppendLine("         lblQuoteBinderExpiresIn.innerText = '(' + dif.toString() + ' days)';");
            sb.AppendLine("    }");
            sb.AppendLine("    else {");
            sb.AppendLine("         lblQuoteBinderExpiresIn.style.visibility = 'hidden';");
            sb.AppendLine("    }");
            sb.AppendLine("}");


            sb.AppendLine("function wdcQuoteBinderValidUntilDate_CalendarValueChanged(oCalendar, oDate, oEvent) {");
            sb.AppendLine("    var now = new Date();");
            sb.AppendLine("    if (lblQuoteBinderExpiresIn == null) {");
            sb.AppendLine("        lblQuoteBinderExpiresIn = document.getElementById('" + lblQuoteBinderExpiresIn.ClientID + "');");
            sb.AppendLine("    }");
            sb.AppendLine("    dif = ((oDate - now)/(86400*1000));");
            sb.AppendLine("    dif = (dif - ( dif % 1 )) + 1;");
            sb.AppendLine("    lblQuoteBinderExpiresIn.innerText = '(' + dif.toString() + ' days)';");
            sb.AppendLine("}");

            sb.AppendLine("function colInsuredState_OnChange(isNewYork) {");
            sb.AppendLine("    var chkNewYorkFreeTradeZone = document.getElementById('" + chkNewYorkFreeTradeZone.ClientID + "');");
            sb.AppendLine("    var lblNewYorkFreeTradeZone = document.getElementById('" + lblNewYorkFreeTradeZone.ClientID + "');");
            sb.AppendLine("    var ddlPolicyType = document.getElementById('" + ddlPolicyType.ClientID + "');");
            sb.AppendLine("    var txtClassCode = document.getElementById('" + txtClassCode.ClientID + "');");
            sb.AppendLine("    var lnkClassCodePrompt = document.getElementById('" + lnkClassCodePrompt.ClientID + "');");
            sb.AppendLine("    var policyTypeId = ddlPolicyType.value;");
            sb.AppendLine("");
            sb.AppendLine("    if(isNewYork) {");
            sb.AppendLine("        chkNewYorkFreeTradeZone.style.visibility = 'visible';");
            sb.AppendLine("        chkNewYorkFreeTradeZone.checked = false;");
            sb.AppendLine("        lblNewYorkFreeTradeZone.style.visibility = 'visible';");
            sb.AppendLine("        txtClassCode.style.visibility = 'visible';");
            sb.AppendLine("        txtClassCode.disabled = false;");
            sb.AppendLine("        lnkClassCodePrompt.disabled = false;");
            sb.AppendLine("        lnkClassCodePrompt.style.visibility = 'visible';");
            sb.AppendLine("        if(policyTypeId == " + (int)Model.REF.EnumPolicyTypes.ENODPL + " ) {");
            sb.AppendLine("             chkNewYorkFreeTradeZone.checked = true;");
            sb.AppendLine("             chkNewYorkFreeTradeZone.disabled = true;");
            sb.AppendLine("             }");
            sb.AppendLine("    }");
            sb.AppendLine("    else {");
            sb.AppendLine("        chkNewYorkFreeTradeZone.parentElement.style.visibility = 'hidden';");
            sb.AppendLine("        chkNewYorkFreeTradeZone.style.visibility = 'hidden';");
            sb.AppendLine("        chkNewYorkFreeTradeZone.checked = false;");
            sb.AppendLine("        lblNewYorkFreeTradeZone.style.visibility = 'hidden';");
            sb.AppendLine("        txtClassCode.value = '';");
            sb.AppendLine("        txtClassCode.disabled = true;");
            sb.AppendLine("        txtClassCode.style.visibility = 'hidden';");
            sb.AppendLine("        lnkClassCodePrompt.disabled = true;");
            sb.AppendLine("        lnkClassCodePrompt.style.visibility = 'hidden';");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("}");
4

4 回答 4

5
  1. 在 Internet Explorer 中:工具 -> Internet 选项 -> 高级

    取消选中“禁用脚本调试(Internet Explorer)”
    取消选中“禁用脚本调试(其他)”

  2. 在你的 JavaScript 脚本的任何地方,添加这个:debugger;

  3. 运行项目并使用 Internet Explorer 打开网页,当提示调试页面时单击是,将打开另一个 VS 实例进行调试:

    在此处输入图像描述

于 2012-07-26T20:24:21.453 回答
3

使用 Firefox 和Firebug插件轻松调试您的 JavaScript。

于 2012-07-26T19:59:07.743 回答
1

您可以直接在 VS2008 及更高版本中调试 javascript,但您必须使用 Internet Explorer 作为默认浏览器进行调试。
如果 IE 当前不是您的默认浏览器,请右键单击解决方案资源管理器中的文件,选择“浏览方式...”,选择 Internet Explorer 并单击“设置为默认值”。现在当你开始在 VS 中调试时,会弹出 IE 并命中 javascript 中的断点。

于 2012-07-26T20:04:13.620 回答
0

这只是一个字符串。您不能从视觉 sutdio 调试字符串。string is string :) 您可以在浏览器上使用以下工具进行调试、监视、添加断点等

  1. 火狐——萤火虫
  2. IE - 开发者工具(F12)
  3. Chrome - 开发者工具
于 2012-07-26T20:07:08.977 回答