2012-07-26 170 views
-3

下面的Javascript是在我的aspx.cs中的Visual Studio中,我已經添加了一個新的腳本,但我不確定我的腳本是否正常工作或沒有..so可以請某人告訴我如何調試下面的代碼....在Visual Studio中調試Javascript

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("}"); 
+1

如果您不知道劇本是否正常工作,其他人怎麼知道? – 2012-07-26 20:00:06

+2

簡單,把你的JavaScript,把它放在一個JS文件,並且不要混合和匹配編程語言。 – zzzzBov 2012-07-26 20:02:17

+0

@ChristoferEliasson ...那是我的問題是關於我從來沒有在Visual Studio中使用java腳本。所以我不知道天氣我錯過了sometng與我的通知....... – user1552588 2012-07-26 20:09:38

回答

3

使用Firefox和Firebug插件方便地調試JavaScript的。

+1

Chrome也一樣,沒有任何插件。 – 2012-07-26 20:00:50

+0

...以及使用開發人員工具的IE。儘管我更喜歡Chrome。 – Nope 2012-07-26 20:02:36

+0

我喜歡Chrome的開發者工具,但Firebug仍然是我的首選JavaScript調試器。 – 2012-07-26 20:13:15

1

您可以在VS2008及更高版本中直接調試javascript,但必須使用Internet Explorer作爲默認瀏覽器進行調試。
如果IE目前不是您的默認瀏覽器,請右鍵單擊解決方案資源管理器中的文件,選擇「瀏覽...」,選擇Internet Explorer,然後單擊「設爲默認值」。現在,當你開始在VS中進行調試時,IE會彈出並在javascript中產生斷點。

0

這只是一個字符串。您無法從visual sutdio調試字符串。字符串是字符串:) 可以調試,手錶,在瀏覽器中添加斷點等下面的工具

  1. Firefox的 - 螢火
  2. IE - 開發工具(F12)
  3. 瀏覽器 - 開發工具
+0

然而,當它被寫入瀏覽器時,他可以使用visual studio和IE作爲jm2的建議進行調試。 – 2012-07-26 20:31:34

+0

他如何使用visual studio觀看chkNewYorkFreeTradeZone.checked值? Visual sutdio不是瀏覽器... – Mehmet 2012-07-26 20:45:00

5
  1. 在Internet Explorer中:工具 - > Internet選項 - >高級

    取消「派息能夠腳本調試器(Internet Explorer)」
    取消選中 「禁止腳本調試(其他)」

  2. 任何地方在你的JavaScript腳本,補充一點:debugger;

  3. 運行該項目,並使用Internet Explorer打開網頁,當提示調試頁面點擊Yes和VS的另一個實例將打開調試:

    enter image description here