2012-09-26 3 views
-4

이 코드의 문제점을 알려주십시오. 경고를 표시하지 않습니다.jquery의 대기 함수

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 
    <script> 
     $(document).ready(function() { 
      $("button").click(function() { 
      alert("hi"); 
     }); 
    }); 
    </script> 

<form id="theform"> 
    <input type="text" name="dt" id="id" value="" /> 
    <input type="button" name="submit" value="submit" /> 
</form> 

답변

2
$("button") 

$("input[type=button]") OR  $("input[name=submit]") 

확인 FIDDLE

선택기는 처음부터 적절한 아니었다이어야한다

$('#btn') // If id of the button is btn 

$('.btn') // If class of the button is btn 
1

html에는 '버튼'유형 태그가 없습니다. 입력 태그입니다.

$(document).ready(function() { 
    $("input[type=button]").click(function() { 
    alert("hi"); 
    }); 
}); 
​ 
+3

거기에 OP의 마크 업에없는 요소가 있습니다. –

+1

마크 업에는 버튼 유형 태그가 없다는 의미입니다. – HungryCoder

1

올바른에게 .. :로 재 작성하십시오 이것을 구현하는 방법은 없습니다. 제출 버튼에 대한 클릭 동작과 관련이 없습니다. 양식의 제출 작업에 연결해야합니다. 좋아요 :

$(document).ready(function() { 
    $("#theform").submit(function() { 
    alert("hi"); 
    }); 
});