亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在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 關注
  • 461 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號