我正在使用 jQuery 2.4.1 最小版本构建一个简单的待办事项列表元素,但创建新待办事项时出现以下错误:
todos.js:12 Uncaught TypeError: event.stopPropogation is not a function
at HTMLSpanElement.<anonymous> (todos.js:12)
at HTMLUListElement.dispatch (jquery-2.1.4.min.js:3)
at HTMLUListElement.r.handle (jquery-2.1.4.min.js:3)
(anonymous) @ todos.js:12
dispatch @ jquery-2.1.4.min.js:3
r.handle @ jquery-2.1.4.min.js:3
Js文件:
$("ul").on("click", "li", function(){
$(this).toggleClass("completed");
});
$("ul").on("click","span",function(event){
$(this).parent().fadeOut(500,function(){
$(this).remove();
});
event.stopPropogation();
});
$("input[type='text']").keypress(function(event){
if(event.which === 13)
{
var todosText=$(this).val();
$(this).val("");
$("ul").append("<li><span>X<span> " + todosText + "<li>");
}
});
最佳答案
您在 event.stopPropogation()
中有拼写错误。您必须编写 event.stopPropagation()
。希望这能解决您的问题。
关于javascript - 创建新的待办事项代码生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59741052/