2017-08-30 26 views
-1

私はHTML、CSS、jQueryを使って簡単なToDoリストを作成しようとしています。私は問題を抱えています。私はそれらを望むように新しいToDoの入力を追加していません。コードはあります。私が間違っているところで。誰かが私が間違っていることをどこに伝えることができますか?

// HTML はここで私は、HTMLタグが、それは私

<head> 
<title>TODO list</title> 
<link rel="stylesheet" type="text/css" href="assests/css/todos.css"> 
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700" rel="stylesheet"> 
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"> 
<script type="text/javascript" src="assests/js/lib/jquery-3.2.1.min.js"></script> 
</head> 
<body> 
    <div id="container"> 
     <h1>TO-DO List<i class="fa fa-plus"></i></h1> 
     <input type="text" placeholder="Add New Todo"> 
     <ul> 
      <li><span><i class="fa fa-trash"></i></span> Go To Potions Class</li> 
      <li><span><i class="fa fa-trash"></i></span> Buy New Robes</li> 
     <li><span><i class="fa fa-trash"></i></span> Visit Hogrid</li> 
     </ul> 
    </div> 
<script type="text/javascript" src="assests/js/todos.js"></script> 
</body> 

// CSS

h1{ 
    background: #2980b9; 
    color: white; 
    margin: 0; 
    padding: 10px 20px; 
    text-transform: uppercase; 
    font-size: 24px; 
    font-weight: normal; 
} 
ul{ 
    list-style: none; 
    margin: 0; 
    padding: 0; 
} 
#container{ 
    box-shadow: 0 0 3px rgba(0,0,0, 0.1); 
    width: 360px; 
    margin: 100px auto; 
    background: #f7f7f7; 
} 

.completed{ 
    color: gray; 
    text-decoration: line-through; 
} 
body{ 
    font-family: 'Roboto', sans-serif; 
    background: #2BC0E4; /* fallback for old browsers */ 
    background: -webkit-linear-gradient(to right, #EAECC6, #2BC0E4); /*  Chrome 10-25, Safari 5.1-6 */ 
    background: linear-gradient(to right, #EAECC6, #2BC0E4); /* W3C, IE 10+/  Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ 

} 
li{ 
    background: white; 
    height: 40px; 
    line-height: 40px; 
    color: #666; 
} 
li:nth-child(2n){ 
    background: #f7f7f7; 
} 

input{ 
    font-size: 18px; 
    background:#f7f7f7; 
    width: 100%; 
    padding: 13px 13px 20px 20px; 
    box-sizing:border-box; 
    color: #2980b9; 
    border:3px solid rgba(0,0,0,0); 
} 
input:focus{ 
    background:white; 
    border: 3px solid #2980b9; 
    outline: none; 
} 

.fa-plus{ 
    float: right; 
} 
span{ 
    background-color: #e74c3c; 
    height:40px; 
    margin-right: 20px; 
    text-align: center; 
    color: white; 
    width:0px; 
    display:inline-block; 
    transition: 0.2s linear; 
    opacity:0; 
} 
li:hover span{ 
    width:40px; 
    opacity:1.0; 
} 

// jQueryの

の罰金に見えるのですそしてここでjQueryのタグです「Web Developer Bootcamp」コースに続いて、これらのコードを使用してTO-DOリストを作成する必要があります。同じコードを書いていますが、新しいTO-Dosを追加したいときには機能しません。私はそれを典型的な方法で表示しています。特定のTODOのの //チェック

$("ul").on("click","li",function(){ 
    $(this).toggleClass("completed"); 
}); 
//click on X to delete TODO 


$("ul").on("click","span",function(event){ 
    //to remove parent lis 
    $(this).parent().fadeOut(500,function(){ 
    $(this).remove(); 
}); 
event.stopPropagation(); 
}); 

//adding new TODO 

$("input[type='text'").keypress(function(event){ 
    if(event.which===13){ 
     //grabbing new TODO text from input 
    var todoText= $(this).val(); 
    $(this).val(""); 
    //create a new li and add to ul 
    $("ul").append("<li><span><i class='fa fa-trash'><span> " + todoText +"</li>") 
    } 
}); 

答えて

2

をクリックして入力するためのセレクタは、右のカッコが欠落しています。

$("input[type='text'") 
+2

これが唯一の問題です。 OPが新しいli要素を追加しているスパンタグを閉じると、目的の動作が達成されます。提供されたjsfiddle https://jsfiddle.net/rg2n8rd8/ – Adriani6

+0

をありがとう、私は明らかにそれを逃した、ありがとう –

関連する問題