为了账号安全,请及时绑定邮箱和手机立即绑定

如何在javascript函数中添加任务?

如何在javascript函数中添加任务?

眼眸繁星 2023-08-24 21:12:17
我有一个HTML/JS如下所示的代码,在单击“执行”按钮时,我想显示:[{"detail":"Hello World"},{"detail":"Great News"}]目前,单击“执行”按钮后,我得到以下信息:[{"detail":""},{"detail":""}]我想知道我需要在下面的 JS 代码中进行哪些更改,以便单击“执行”按钮时,我能够显示:[{"detail":"Hello World"},{"detail":"Great News"}] HTML: <input type="submit" onClick="runCode()" value="Execute" > <div id="console-log"> </div>JavaScript:$(document).ready(function() { })function runCode(){var td=new Todo()td.addTask("Hello World")td.addTask("Great News")td.printList()}class Todo{    constructor(name) {        this.todolist = [];                        this.task={            'detail':''        }      }        addToList(newobj)    {        this.todolist.push(newobj)         }    addTask(taskDetail){                        this.task.detail=taskDetail            this.todolist.push(this.task)            this.task.detail='' //clear data for next step        }    printList()    {            var consoleLine = "<p class=\"console-line\"></p>";            var text= JSON.stringify(this.todolist)         $("#console-log").append($(consoleLine).html(text));        //alert(this.todolist)    }}
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 304 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信