开发者

Select box calling another element’s click event jquery

开发者 https://www.devze.com 2022-12-18 22:40 出处:网络
I have a div on my page witch is hidden : AddSupplier, I have a button on my page witch must show the div if its not visible, but the same button saves some stuff if the div is visible. So all that is

I have a div on my page witch is hidden : AddSupplier, I have a button on my page witch must show the div if its not visible, but the same button saves some stuff if the div is visible. So all that is working but in this AddSupplier div there is a select box "ddSupplierTypes" and when the select box gets clicked the AddSupplierButton click event gets triggered why is this, and is there a work around?

Tanks for any help.

<%@ Page Language="C#" %>  
<html> 
     <head runat="server"> 
     <script src="Scripts/jquery-1.4.min.js" type="text/javascript"></script> 
     <script type="text/javascript"> 

     $().ready(function() { 
         $('#AddSupplier').hide(); 
         $('[id$=AddSupplierButton]').click(function() { 
             if ($('#AddSupplier').is(':visible')) { 
                 //do this 
                 alert('ev开发者_StackOverflow社区ent fired'); 
             } else { 
                 //do that 
                 $('#AddSupplier').show(); 
             } 

             return false; 
         }); 
     }); 

 </script> </head> <body> 
 <form id="form1" runat="server"> 
 <div id="wrapper"> 
 <asp:ImageButton ID="AddSupplierButton" runat="server" Height="18px"  
 ImageUrl="~/images/add.png" OnClientClick="return(false);"/> 
 </div> 
 <div id="AddSupplier"> 
     <select id="ddSupplierTypes"> 
     <option value="S">ss</option> 
     <option value="F">kk</option> 
     <option value="W">oo</option> 
     <option value="P">ii</option> 
     </select> 
 </div> 
 </form>     
</body> 
</html>


It ought to work as far as I can see.

Can you test the following code in your document ready function

alert($('[id$=AddSupplierButton]').length);

How many objects are returned?


I tried to simplify the above code but forgot to mention that im working with master pages. So on my Master Page i got this image button control

<asp:ImageButton ID="AddVerskaffer" OnClientClick="return(false);"/>

witch i call in jQuery as '[id$=AddSupplierButton]' because the master page changes the control name to some long ID.

Any now I replaced the asp image button with a normal link

<a id="AddVerskaffer" href="javascript:void(0);"  ></a>

and now it works. No event gets fired when clicking on the select box.

Why do you think this happens?

0

精彩评论

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