How to use JQuery with Master Pages?

后端 未结 13 1123
甜味超标
甜味超标 2020-12-04 18:13

I can get simple examples to work fine as long as there\'s no master page involved. All I want to do is click a button and have it say \"hello world\" with the javascript in

相关标签:
13条回答
  • 2020-12-04 19:03

    Master page:

    The jQuery library goes in the master page. See if the path is correctly referenced. You might like to add the extra documentation like this:

    <head>
        <script type="text/javascript" src="/Scripts/jquery-1.2.6.min.js"></script> 
        <% if (false) { %>
        <script type="text/javascript" src="/Scripts/jquery-1.2.6-vsdoc.js"></script>
        <% } %>
    </head>
    

    Master page:

    <head>
    <script type="text/javascript">
        $(document).ready(
            function()
            {
                alert('Hello!');
            }
        );
    </script>
    </head>
    

    CodeBehind for content pages and user controls:

    this.textBox.Attributes.Add("onChange",
        String.Format("passElementReferenceToJavascript({0})", this.textBox.ClientID));
    
    0 讨论(0)
提交回复
热议问题