asp.net我无法在脚本部分调试javascript

asp.net I cannot debug javascript in script section

本文关键字:脚本部 调试 javascript net asp      更新时间:2023-09-26

我有一个简单的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键启动,然后单击按钮时,应用程序不会在断点处停止。只有当我在没有调试的情况下通过Start运行我的项目时,它才会停止,然后在Mozilla(firebug)中,我可以在这个函数中设置断点,当我按下按钮时它就会停止。如何在Visual中调试?不在Mozilla?

感谢

右键单击项目中的页面,如Default.aspx,然后选择"浏览方式…"。。。菜单项。

显示对话框时,选择Internet Explorer,然后单击"设置为默认值"按钮,然后按"取消"按钮。

打开internet explorer,转到"internet选项"对话框,单击"高级"选项卡,并确保在"浏览"部分下,未选中"禁用脚本调试(internet explorer)"。

然后,为了强制调试,您可以添加javascript调试器;javascript方法正文的行:

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

当您以这种方式调试时,internet explorer将使您能够选择要使用的应用程序和实例,其中一个选项将是internet explorer。

还有其他方法可以将调试器从Visual Studio web应用程序项目中附加到internet explorer实例,例如选择"附加到进程…"。。。从"调试"菜单中,选择iexplore.exe的实例,该实例的类型列为"脚本",并且正在运行您感兴趣的调试页面。

调试器关键字放在要调试的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>

您可以在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);
            }
        }