有關於VS調試Javascript的問題

來源:互聯網
上載者:User

1、從微軟網站下載MS Script Debugger並安裝,這是:
http://download.microsoft.com/download/winscript56/install/1.0a/NT45XP/EN-US/scd10en.exe

2、修改IE的設定:
IE的選項-->進階,有兩個選項預設是鉤選的:
Disable Script Debugging(Internet Explorer)
Disable Script Debugging(Other)
中文可能是“禁用指令碼調試”,去掉這兩項的鉤選。

3、在需要調試的地方加上debugger;例如: <script language=javascript>
..
debugger;
..
</script>
這就是一個斷點,當運行到這裡的時候就會中斷進入偵錯模式:

1。設定IE進階選項,把禁止調試去掉

 

2。讓後開啟你要調試的頁面

 

3。回到vs2003中,選擇工具-調試進程--選擇explorer.exe--附加--選擇script確定

 

4.選擇debug-window-running document

這樣就可以單步運行你的用戶端指令碼了

 


在Fitch and Mather 7.0項目中發現2個常用的javascript

1。頁面啟動時聚焦某一個文字框

 

例如頁面中有一個文字框

<asp:textbox id="b" runat="server">start</asp:textbox>

 

加入下面的指令碼

function window_onload()

{

       if (document.all.b)

       {

              document.all.b.select();

              document.all.b.focus();

       }

}

 

再添加

<body onload="window_onload()">

 

2。文字框內容改變時的互清除內容

例如頁面中有2個文字框

<asp:textbox id="b" onpropertychange="OnEditHandler()" runat="server"></asp:textbox>

<asp:textbox id="a" onpropertychange="OnEditHandler()" runat="server"></asp:textbox>

 

var inHandler=false;                                                               

function OnEditHandler()

{

       if(inHandler)

               return;

        inHandler=true;

       var srcId = event.srcElement.id;               

                               

       if( srcId == "a" )

       {                  

          document.all.b.value = "";                  

       }

       else if( srcId == "b" )

       {                  

          document.all.a.value = "";                  

       }

         inHandler=false;

}

 

這樣當a中內容改變時,就清空b中的文本,同樣當b中內容改變時,就清空a中的文本

-------------------------------------------------------------------------------------------------
Visual Studio  

調試用戶端指令碼
Microsoft Visual Studio .NET 調試器向您提供了用於測試和更正 Web 文檔指令碼中的錯誤的綜合調試環境。您可以使用 Visual Studio .NET 調試器測試用 Microsoft Visual Basic Scripting Edition (VBScript) 和 Microsoft JScript 編寫的指令碼。

可以使用 Visual Studio .NET 調試器調試 ASP.NET 頁中的用戶端指令碼。用戶端指令碼由 HTML 頁中的語句組成。Microsoft Internet Explorer 在載入文檔或響應事件(如按鈕單擊事件)時執行該指令碼。

在用戶端指令碼中設定斷點
要在用戶端指令碼中設定斷點,不能只是在項目 .aspx 檔案中設定斷點。.aspx 檔案是伺服器端文檔,在其中設定的斷點不翻譯為用戶端文檔。相反,您可以使用以下方法之一設定用戶端斷點。

在用戶端指令碼中設定斷點

將所有用戶端指令碼寫入一個函數,並在該函數上設定函數斷點。
- 或 -

從“運行文檔”視窗開啟用戶端指令碼並在其中設定斷點。
啟用指令碼調試
注意   預設情況下,Internet Explorer 中禁用指令碼調試。若要調試用戶端指令碼應用程式,必須首先在 Internet Explorer 中啟用指令碼調試。
在 Internet Explorer 5.5 或更高版本中啟用指令碼調試

從“工具”菜單中選擇“Internet 選項”。
在“Internet 選項”對話方塊中,選擇“進階”選項卡。
在“瀏覽”類別中,清除“禁用指令碼調試”複選框。
單擊“確定”。
此外,要命中用戶端指令碼中的斷點,必須設定一個名為 ASPCLIENTDEBUG Cookie 的 Cookie。如果尚未自動化佈建此 Cookie,可使用下列過程手動設定它。

手動設定 ASPCLIENTDEBUG Cookie

建立包含以下代碼的 HTML 文字檔:
<html>
<head>

<script language="JavaScript">

function set ()
{
    var expdate = new Date();
    expdate.setMonth(expdate.getMonth()+6);
   alert("setting cookie \""+form1.txtName.value+"\" to \""+form1.txtValue.value+"\"");
    setCookie(form1.txtName.value, form1.txtValue.value, expdate);
}

function get ()
{
   alert("getting cookie \""+form1.txtName.value+"\"");
    var c = getCookie(form1.txtName.value);
    alert( "cookie = "+c );

    form1.txtValue.value = c;
}

function getCookie (sCookieName)
{
    var sName=sCookieName+"=", ichSt, ichEnd;
    var sCookie=document.cookie;

    if ( sCookie.length && ( -1 != (ichSt = sCookie.indexOf(sName)) ) )
    {
        if (-1 == ( ichEnd = sCookie.indexOf(";",ichSt+sName.length) ) )
            ichEnd = sCookie.length;
        return unescape(sCookie.substring(ichSt+sName.length,ichEnd));
    }
   
    return null;
}
  
function setCookie (sName, vValue)
{
    var argv = setCookie.arguments, argc = setCookie.arguments.length;
    var sExpDate = (argc > 2) ? "; expires="+argv[2].toGMTString() : "";
    var sPath = (argc > 3) ? "; path="+argv[3] : "";
    var sDomain = (argc > 4) ? "; domain="+argv[4] : "";
    var sSecure = (argc > 5) && argv[5] ? "; secure" : "";
    document.cookie = sName + "=" + escape(vValue,0) + sExpDate + sPath + sDomain + sSecure + ";";
}
   
function deleteCookie (sName)
{
    document.cookie = sName + "=" + getCookie(sName) + "; expires=" + (new Date()).toGMTString() + ";";
}

</script>

</head>

<body>

<form name=form1>
   cookie name:<input type="text" name="txtName" value="ASPCLIENTDEBUG"><p>
   cookie value:<input type="text" name="txtValue" value="doesn't matter"><p>
   <input type="button" value="Set Cookie" onClick="set()">
   <input type="button" value="Get Cookie" onClick="get()">
</form>
</body>
</html>
將此檔案儲存為 cookie.html。
將此檔案複製到
c:\inetput\wwwroot
在 Internet Explorer 的“地址”框中,鍵入:
http://localhost/cookie.html
在 http://localhost/cookie.html 視窗中,單擊“設定 Cookie”按鈕。
增強指令碼調試錯誤資訊
Visual Studio .NET 2003 為常見的指令碼調試問題提供增強錯誤資訊。除非手動附加到 Internet Explorer 而不是讓調試器自動啟動 Internet Explorer,否則您通常不會看到這些訊息。如果遇到問題,請使用下列過程手動附加並獲得更多資訊。

手動附加

從“調試”菜單中選擇“進程”。
出現“進程”對話方塊。

如果已經開始調試,請轉到“已調試的進程”列表。選擇正在調試的進程並單擊“分離”。
在“可用進程”框中,找到 Internet Explorer (iexplore.exe),選擇它並單擊“附加”。
在“附加到進程”對話方塊中的“選擇要調試的程式類型”下,只選擇“Script”。
單擊“確定”。
此時可能出現錯誤資訊框。若是如此,請單擊“協助”按鈕以獲得更多資訊。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.