我試過了,但是當點擊十字按鈕時我似乎不能刪除列表。有人可以解釋爲什麼'這個'在這裏不起作用嗎? 或者還有其他方法可以知道除了使用'this'對象之外哪個十字按鈕被點擊?javascript中的這個對象不起作用
$(function(){
\t $("#btn").on("click",function(){
\t var text = $("#input").val();
\t if(text==""){
\t \t alert("please enter a task!");
\t }
\t else{
\t var task = $("<li></li>").text(text);
\t $(task).append("<button class= 'rem'>X</button>");
\t $("#ordered").append(task);
\t }
});
\t $(".rem").on("click",function(){
\t \t $(this).hide(1000);
\t });
});
<!DOCTYPE html>
<html lang = "en">
<head>
\t <title>Javascript Addition</title>
\t <meta charset = "utf-8">
\t
\t </head>
\t <body>
\t \t <h1>My To-Do List </h1>
\t \t <input id = "input" placeholder ="Add your task Here...">
\t \t <button id = "btn">clickkk</button>
\t \t <ol id = "ordered">
\t \t \t </ol>
\t \t <script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="todo.js"></script>
</body>
</html>