2012-08-05 24 views
1

我有簡單的JavaScript函數:asp.net我不能調試腳本部分的JavaScript

<form id="form1" runat="server"> 
    <script type="text/javascript"> 

     function doSomething(message) { 
     var div1 = document.getElementById('div1'); 
     div1.innerHTML = 'afas'; 
    } 

    </script> 

<telerik:RadButton ID="btnShowUpload" runat="server" OnClientClicked="doSomething('test1')" Text="Upload file"> 
    </telerik:RadButton> 

當我設置的函數斷點OnClientClicked和F5開始,然後單擊按鈕,應用程序不停在斷點處。它只會停止當我運行我的項目開始沒有調試,然後在Mozilla(螢火蟲)我可以在此功能中設置斷點,它停止時,我按下按鈕。如何在Visual中進行調試?不在Mozilla中?

感謝

回答

2

在您的項目,如Default.aspx的頁面上單擊鼠標右鍵,並選擇瀏覽方式。 ..菜單項。

當顯示的對話框中,選擇IE瀏覽器,然後單擊設爲默認值按鈕,然後按下取消按鈕。

打開Internet Explorer,轉到Internet選項對話框,單擊高級選項卡上,並確保在瀏覽部分,禁用腳本調試(Internet Explorer)中沒有檢查。

然後,迫使調試,您可以添加JavaScript調試器;行到您的JavaScript方法的主體:

function doSomething(message) { 
    debugger; 
    // rest of your code 

當您調試這種方式,Internet Explorer將讓你選擇要使用的應用程序和實例,其中一個選項將是Internet Explorer中的能力。

還有其他一些方法可以將調試器從Visual Studio Web應用程序項目中附加到Internet Explorer實例,例如從Debug菜單中選擇Attach To Process ...並選擇iexplore.exe的實例在類型列中列出了一種類型的腳本,它正在運行您感興趣調試的頁面。

0

,你可以在你的JavaScript設定調試指令斷點 -

function OnClientClicked(button, args) { 
      debug; 
      if (window.confirm("Are you sure you want to submit the page?")) { 
       button.set_autoPostBack(true); 
      } 
      else { 
       button.set_autoPostBack(false); 
      } 
     } 
0

把要調試Java腳本代碼之前調試關鍵字。

<form id="form1" runat="server"> 
    <script type="text/javascript">  
    //enable debugging javascript code   
    debugger; 
    function doSomething(message) { 
    var div1 = document.getElementById('div1'); 
    div1.innerHTML = 'afas'; 
} 

</script>