简体   繁体   中英

jQuery highlight effect not working?

Here is my ascx page with embedded javascript.

I'd like to highlight the view which I have wrapped in a div tag (div2 for test purposes) when the view changes.

As of now the views change fine, but I cannot get the highlight to work.

Is something wrong with my javascript or am I missing something else??

Thanks

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



<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:MultiView ID="MultiView1" runat="server">

<asp:View ID="View1" runat="server">
   <p>This is View 1</p>
   <asp:Button ID="Button1" runat="server" Text="Next" onclick="Button1_Click" />
 </asp:View>


 <asp:View ID="View2" runat="server">
    <div id="div2" style="height:auto; width:auto;">
    <p>This is View 2</p>
    <asp:Button ID="Button2" runat="server" Text="Previous" 
        onclick="Button2_Click" />  
    <asp:Button ID="Button3" runat="server" Text="Next" onclick="Button3_Click" /> 
    </div>

    <script type="text/javascript">
    $(document).ready(function () {
    $("#Button1").click(function () {
    $("#div2").effect("highlight", {}, 3000);
    });
    });
    </script>

 </asp:View>


 <asp:View ID="View3" runat="server">
    <p>This is View 3</p>
    <asp:Button ID="Button4" runat="server" Text="Previous" 
        onclick="Button4_Click1" />

 </asp:View>

 </asp:MultiView>

  </ContentTemplate>
 </asp:UpdatePanel> 

Code Behind:

namespace Multiview1.Multiview1
{
public partial class Multiview1UserControl : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
    }

   protected void Button1_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View2);
        UpdatePanel1.Update();
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View3);
        UpdatePanel1.Update();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
        UpdatePanel1.Update();
    }

    protected void Button4_Click1(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View2);
        UpdatePanel1.Update();
    }
  }
 }

The problem appears to be loading multiple versions of jquery.

I've set up a fiddle to show the issue. When the 2nd jquery library is commented out it works fine when it's not it doesn't work at all.

Jsfiddle

use your Button click like this

$("#<%=Button1.ClientID%>").click(function () {
    $("#div2").effect("highlight", {}, 3000);
   });
});

As it is an asp.net control.

EDIT : You are going in wrong direction there is nothing wrong with the jquery click, Problem here is your div tags are inside updatepanel check this LINK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM