2011-03-15 2 views
1

메시지 버튼을 클릭하면 alert()를 호출하지 않습니다. 누군가 코드를 확인하십시오.버튼이 alert()을 호출하지 않습니다

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Homepage</title> 
    <script type="text/javascript" src="lib/jquery/jquery-1.4.2.js"></script> 
    <script type="text/javascript" src="lib/jquery/jquery-ui-1.8.10.custom.min.js"></script> 
    <script type="text/javascript" src="lib/jquery/jquery.dmDropDownMenu.js"></script> 
    <script type="text/javascript" src="lib/jquery/watermark.js"></script> 

    <link rel="stylesheet" type="text/css" href="/jquery-ui-1.8.10.custom.css" /> 
    <link rel="stylesheet" type="text/css" href="/stylez.css" /> 
    <script type="text/javascript" /> $(document).ready(function(){ $('#buttons button').click(function(){ switch($('buttons').id){ case "mail": alert(1); break; } }); }); </script> 
</head> 

<body> 
    <table width="1000" border="0" cellpadding="0" cellspacing="0"> 
     <tr> 
      <td id="columnA">  
       <div id="buttons"> 
        <button id="mail" class="menubutton">Message</button><br/> 
       </div> 
      </td> 
     </tr> 
    </table>  
</body> 

</html> 

답변

2

당신이 클릭 된 당신은 당신이 .click() 내부 $(this)을 사용할 수 있으며, 여러 개의 버튼이 예정되어있는 버튼을 확인하려면 , 클릭 된 THE을 참조합니다.

switch($(this).attr('id')) { 

전체 많은 : 그래서 스위치를 변경

$('#buttons button').click(function(){ 
    switch($(this).attr('id')){ 
     case "mail": 
      alert(1); 
     break; 
    } 
}); 

[0] .id` ('버튼') 작업 demo here

2

변화

$('buttons').id 

에 :

$('buttons').get(0).id 
+2

또는 단지'$를 참조하십시오. –

관련 문제