【问题标题】:Creation of new todos code generating error创建新的 todos 代码生成错误
【发布时间】:2020-05-01 14:36:13
【问题描述】:

我正在使用 jQuery 2.4.1 min 版本构建一个简单的待办事项列表项目,但创建新待办事项时出现以下错误:

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>");

    }

});

【问题讨论】:

    标签: javascript jquery html css error-handling


    【解决方案1】:

    您在event.stopPropogation() 中有拼写错误。你必须写event.stopPropagation()。希望这能解决您的问题。

    【讨论】:

    • 是的,它确实消除了错误,但新待办事项的创建仍然无法正常运行。
    • 在附加 html 时,您还缺少结束标记中的“/”。就像
    • 的结束标记一样,它应该是
    • 也是如此。
  • 这是正确的答案。如果您仍然有问题,您应该提出一个新问题。
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签