C# 在asp.net页面中使用JavaScript

C# 在asp.net页面中使用JavaScript,c#,javascript,asp.net,C#,Javascript,Asp.net,我可能有一个非常简单的问题 我已经将代码复制到我的asp.net web应用程序项目中,但我无法最小化该框 要在asp.net项目中使用javascript,我应该做些什么 我试了几次代码树 将脚本代码放入头块 在div开始之前将脚本代码放到 在表单标记关闭之前将脚本代码放入 Javascript代码 $("#button").click(function(){ if($(this).html() == "-"){ $(this).html("+"); }

我可能有一个非常简单的问题

我已经将代码复制到我的asp.net web应用程序项目中,但我无法最小化该框

要在asp.net项目中使用javascript,我应该做些什么

我试了几次代码树

  • 将脚本代码放入头块
  • 在div开始之前将脚本代码放到
  • 在表单标记关闭之前将脚本代码放入
  • Javascript代码

    $("#button").click(function(){
        if($(this).html() == "-"){
            $(this).html("+");
        }
        else{
            $(this).html("-");
        }
        $("#box").slideToggle();
    });
    
    html代码

    <div id="widnow">
        <div id="title_bar"> Basic information
            <div id="button"><img src="http://commons.wikimedia.org/wiki/File:Minus_in_circle.svg"></div>
        </div>
        <div id="box">
        </div>
    </div>
    

    我假设您缺少对jquery的引用。如果是这样的话,用这个替换脚本部分可以解决问题

    <script src="code.jquery.com/jquery-1.10.2.min.js"></script>
    // or use any version of jquery library..in your fiddle you used 1.7.2..Try the same instead..
    <script>
    $("#button").click(function(){
        if($(this).html() == "-"){
            $(this).html("+");
        }
        else{
            $(this).html("-");
        }
        $("#box").slideToggle();
    });
    </script>
    
    
    //或者使用任何版本的jquery库..在您的小提琴中使用了1.7.2..尝试相同的方法。。
    $(“#按钮”)。单击(函数(){
    如果($(this.html()=“-”){
    $(this.html(“+”);
    }
    否则{
    $(this.html(“-”);
    }
    $(“#框”).slideToggle();
    });
    
    我假设您缺少对jquery的引用。如果是这样的话,用这个替换脚本部分可以解决问题

    <script src="code.jquery.com/jquery-1.10.2.min.js"></script>
    // or use any version of jquery library..in your fiddle you used 1.7.2..Try the same instead..
    <script>
    $("#button").click(function(){
        if($(this).html() == "-"){
            $(this).html("+");
        }
        else{
            $(this).html("-");
        }
        $("#box").slideToggle();
    });
    </script>
    
    
    //或者使用任何版本的jquery库..在您的小提琴中使用了1.7.2..尝试相同的方法。。
    $(“#按钮”)。单击(函数(){
    如果($(this.html()=“-”){
    $(this.html(“+”);
    }
    否则{
    $(this.html(“-”);
    }
    $(“#框”).slideToggle();
    });
    
    您很可能缺少jquery文件……试试这个

    <html>
    <head runat="server">
        <title></title>
        <style>
            #widnow
            {
                width: 400px;
                border: solid 1px;
            }
    
            #title_bar
            {
                background: #FEFEFE;
                height: 25px;
                width: 100%;
            }
            #button
            {
                border: solid 1px;
                width: 25px;
                height: 23px;
                float: right;
                cursor: pointer;
            }
            #box
            {
                height: 250px;
                background: #DFDFDF;
            }
        </style>
        <script src="Scripts/jquery-1.10.1.js" type="text/javascript"></script>
        <script>
            $(document).ready(function () {
                $("#button").click(function () {
                    if ($(this).html() == "-") {
                        $(this).html("+");
                    }
                    else {
                        $(this).html("-");
                    }
                    $("#box").slideToggle();
                });
            });
        </script>
    </head>
    <body>
        <div id="widnow">
            <div id="title_bar">
                Basic information
                <div id="button">
                    <img src="http://commons.wikimedia.org/wiki/File:Minus_in_circle.svg"></div>
            </div>
            <div id="box">
            </div>
        </div>
    </body>
    </html>
    
    
    #维德诺
    {
    宽度:400px;
    边框:实心1px;
    }
    #标题栏
    {
    背景:#FEFEFE;
    高度:25px;
    宽度:100%;
    }
    #钮扣
    {
    边框:实心1px;
    宽度:25px;
    高度:23px;
    浮动:对;
    光标:指针;
    }
    #盒子
    {
    高度:250px;
    背景:#dfdf ;;
    }
    $(文档).ready(函数(){
    $(“#按钮”)。单击(函数(){
    如果($(this.html()=“-”){
    $(this.html(“+”);
    }
    否则{
    $(this.html(“-”);
    }
    $(“#框”).slideToggle();
    });
    });
    基本信息
    
    您很可能缺少jquery文件……试试这个

    <html>
    <head runat="server">
        <title></title>
        <style>
            #widnow
            {
                width: 400px;
                border: solid 1px;
            }
    
            #title_bar
            {
                background: #FEFEFE;
                height: 25px;
                width: 100%;
            }
            #button
            {
                border: solid 1px;
                width: 25px;
                height: 23px;
                float: right;
                cursor: pointer;
            }
            #box
            {
                height: 250px;
                background: #DFDFDF;
            }
        </style>
        <script src="Scripts/jquery-1.10.1.js" type="text/javascript"></script>
        <script>
            $(document).ready(function () {
                $("#button").click(function () {
                    if ($(this).html() == "-") {
                        $(this).html("+");
                    }
                    else {
                        $(this).html("-");
                    }
                    $("#box").slideToggle();
                });
            });
        </script>
    </head>
    <body>
        <div id="widnow">
            <div id="title_bar">
                Basic information
                <div id="button">
                    <img src="http://commons.wikimedia.org/wiki/File:Minus_in_circle.svg"></div>
            </div>
            <div id="box">
            </div>
        </div>
    </body>
    </html>
    
    
    #维德诺
    {
    宽度:400px;
    边框:实心1px;
    }
    #标题栏
    {
    背景:#FEFEFE;
    高度:25px;
    宽度:100%;
    }
    #钮扣
    {
    边框:实心1px;
    宽度:25px;
    高度:23px;
    浮动:对;
    光标:指针;
    }
    #盒子
    {
    高度:250px;
    背景:#dfdf ;;
    }
    $(文档).ready(函数(){
    $(“#按钮”)。单击(函数(){
    如果($(this.html()=“-”){
    $(this.html(“+”);
    }
    否则{
    $(this.html(“-”);
    }
    $(“#框”).slideToggle();
    });
    });
    基本信息
    
    这里的示例在小提琴中工作得很好。项目中是否引用了jQuery?是否包含jQuery库的路径?将code.jquery.com/jquery-1.10.2.min.js“>放在脚本之前。您是否正确地包含jquery文件此处的示例在小提琴中运行良好。您的项目中是否引用了jquery?您是否包含到jquery库的路径?将code.jquery.com/jquery-1.10.2.min.js放在“中”>在您的脚本之前。您是否正确包含jquery文件?我发现问题在于正确添加jquery文件。谢谢我发现问题在于正确添加jquery文件。谢谢