下面是我的代碼,爲什麼當我點擊附加文本?如何使用兩個'onclick'事件
1:點擊這是一段。
2:點擊附加文本
3:須出示追加項目與紅色。
$(document).ready(function(){
$(".ali").click(function(){
$(this).parent().append("<b class='reza'>Appended text</b>");
});
$(".reza").click(function(){
$(this).append("<li style='color:red'>Appended item</li>");
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<p><span class="ali"> This is a paragraph. </span> </p>
</body>
</html>
的[事件綁定上動態創建的元素?]可能的複製(https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – Xufox