2016-06-02 3 views
-2

어떻게 든 내 코드에서 정의되지 않은 값을 계속 가져옵니다. 나는 아마 뭔가를 놓쳤을 지 모르지만 실제로 무엇을 알아낼 수는 없습니다.정의되지 않은 값. 자식(). 각()

옥 :

function toggleOrder(){ 
$('a#order').click(function(){ 
    $(".orderform").delay(200).toggle("slide", { 
    direction: "right", 
    duration: 1000, 
    easing: 'easeInOutQuint', 
    }); 

코드 정의되지 않은 값을 내 놓는다 :

자바 스크립트/jQuery를 필요한 경우 내가 html 코드를 추가 할 수 있습니다

.orderform 
a(class="nav-button closebutton black", id="order") 
    i(class="fa fa-times" aria-hidden="true") 
form(method="post") 
    h1 Order Form 
    p [...] 
    .inputfield 
    input(type="text", name="fname", autofocus) 
    label First Name 
    .inputfield 
    input(type="text", name="fname") 
    label Last Name 
    .inputfield 
    input(type="email", name="email") 
    label Email 
    .inputfield 
    input(type="text", name="subject") 
    label Subject 
    .inputfield 
    textarea(type="email", name="email") 
    label Comment 
    input(type="submit", value="order") 

$("form").children().each(function(){ 
    alert(this.value); 
    //setTimeout(function(){ 
    //$(this).eq(i).addClass('shown'); 
    //}, 500 * (i+1) + 600); 
    }); 
}); 
} 

그래서 전용 버튼을 누르면 정의되지 않은 값이 경고됩니다. 내가 뭔가를 놓치거나 코드를 다시 작성해야합니까?

+1

이 양식에 요소가없는 다음 여기로 들여 쓰기가 동일 잘합니다. – Craicerjack

+1

또한'$ ("form"). children()'은 폼에서 h1과 p라는 모든 즉각적인 요소를 반환하며 값을 가지고 있지 않습니다. 대신에'$ ("form"). find (": input")'를 쓰면된다. – JJJ

+0

'children()'은 한 레벨 아래에서만 검색하므로'h1','p','.inputfield'와 1'put'을 루핑합니다. 마지막 부분을 제외하고는 모두 'value' 속성이 없습니다. – Rhumborl

답변

0

$ ("양식") 어린이() 반환 이러한 요소 :.

h1 
p 
div.inputfield (5 items) 
input[type="submit"] 

그래서 당신은이 요소에서 값을 얻기 위해 노력하고 있습니다.

모든 inputfields에 클래스를 추가해야하는 경우 사용할 수 있습니다

$(".orderform form .inputfield").each(function(i){ 
    var _this = $(this); 
    setTimeout(function(i){ 
     _this.addClass('shown'); 
    }, 500 * (i+1) + 600); 
}); 
관련 문제