开发者

JQuery not working

I am trying to implement JQuery in my web page but i am not been able to implement it successfully.

I have a master page

where i added one script for menu bar that is already using jquery hosted by Google

This is coded in master page itself

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>

Now i want to implement a Jquery to set the css visibility property to true or false. into my content page of same master page.

    <script type="text/javascript">
            $(document).ready(function(){  
                $("#lnkAddMore").click(function(){
               开发者_Python百科  alert();
                  }
                  );
            });
        </script>

This html control is under my UpdatePanel. I dont know why it is not working ? I am using this control under UpdatePanel.

<input type="button" id="lnkAddMore" value="Add More" />

I tried to use it outside my update panel it is running successfully but not in UpdatePanel

I think there is a problem using it with an UpdatePanel

HERE IS MY PAGE SOURCE

   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script> 


    <link href="../../Css/Domain.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript"> 
        $(document).ready(function(){  
            $("#lnkAddMore").click(function(){alert();$('#h').hide(100);});
            $('#h').show(100);
        });
    </script> 


       <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div id="divDomain" runat="server">
<asp:gridview/>
                <div style="text-align:right;">
                    <input type="button" id="lnkAddMore" value="Add More" />
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>


Do you really have nested <script> tags or was it a typo?

<script type="text/javascript">

<script type="text/javascript">

If that's not a typo, then that's probably the issue.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {  
        $('#ddmenu > li').bind('mouseover', ddmenu_open)
        $('#ddmenu > li').bind('mouseout',  ddmenu_timer)
    });

    $(document).bind('click', ddmenu_close); // do you really want to close on any click?
</script>


I have used two approaches with jQuery and UpdatePanels.

The first is this: jQuery $(document).ready and UpdatePanels?

The other approach I found on Rick Strahl's blog (http://www.west-wind.com/Weblog/posts/154797.aspx) Which is to do something like this in the code behind:

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alertScript", 
    @" $(document).ready(function(){  
            $("#lnkAddMore").click(function(){
             alert();
              }
              );
        });", true);

Check this out for another example: Problem with ScriptManager.RegisterClientScriptBlock and jQuery in Internet Explorer 8

Also have a look at jQuery's live() event subscriber.


Check that the ID of your button isn't actually getting changed to something like

ctl00_ContentPlaceHolder1_lnkAddMore

since it's residing in a content placeholder for the master page.

If it is, you'd have to adjust your JQuery.


When you're loading code in under an UpdatePanel, try not wrapping it in $(document).ready();. Ready isn't fired on document for AJAX events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜