2014-03-17 2 views
-3

jQuery 코드 :Jquery 코드가 잘못되었습니다. 어떤 1?

$(document).ready(function(){ 

    $("#button").click(function(){ 
     var toAdd = $("input[.list = checkListItem]").val();  
    }); 
}); 

HTML 코드 :

<!DOCTYPE html> 
<html> 
    <head> 
     <title>To Do</title> 
     <link rel="stylesheet" type="text/css" href="stylesheet.css"/> 
     <script type="text/javascript" src="script.js"></script> 
    </head> 
    <body> 
     <h2>To Do</h2> 
     <form name="checkListForm"> 
      <input type="text" name="checkListItem"/> 
     </form> 
     <div id="button">Add!</div> 
     <br/> 
     <div class="list"></div> 
    </body> 
</html> 

CSS 코드 :

h2 { 
    font-family:arial; 
} 

form { 
    display: inline-block; 
} 

#button{ 
    display: inline-block; 
    height:20px; 
    width:70px; 
    background-color:#cc0000; 
    font-family:arial; 
    font-weight:bold; 
    color:#ffffff; 
    border-radius: 5px; 
    text-align:center; 
    margin-top:2px; 
} 

.list { 
    font-family:garamond; 
    color:#cc0000; 
} 

또한 여기에 내가 뭘 운동에 대한 libk입니다 : http://www.codecademy.com/courses/web-beginner-en-v6phg/2/2?curriculum_id=50a3fad8c7a770b5fd0007a1

가 여기에 오류가 있습니다. "죄송합니다, 다시 시도하십시오. 우리의 toAdd 변수에는 올바른 값이 없습니다. 도움이 필요하면 힌트를 확인 "

+1

에서 val input = $ ('input [name = checkListItem]') .Val();'그래서 당신의 질문은 무엇입니까? ??? selector가 작동하지 않는 이유 –

+0

$ ("input [ 이름 = checkL istItem] ") –

답변

1

을 원하는처럼 보인다!

var toAdd = $("input[name=checkListItem]").val(); 

대신 :.

var toAdd = $("input[.list = checkListItem]").val(); 

을 당신이 당신의 input 요소에 name="checkListItem"를 할당 한 이후

관련 문제