1

我有以下带有Deno运行时的代码,它在网站上显示一个按钮:

  1. 如何更改此按钮的属性
  2. 如何为此按钮添加 eventListner
import { serve } from "https://deno.land/std@v0.24.0/http/server.ts"

async function main() {
    const body = new TextEncoder().encode(`<button>click me</button>\n`);
    const s = serve({ port: 8000 });
    console.log(`Server had been started at: http://localhost:8000/`);
    for await (const req of s) {
      req.respond({ body });
    }
};

main()
4

1 回答 1

2

通过更换

<button>click me</button>\n

<button id='button' onclick="document.getElementById('button').innerHTML='wow I changed'">click me</button>\n

或另一个单独添加 eventListener 的示例

`<button id='button'>click me</button><script>document.getElementById('button').addEventListener('click',function(){document.getElementById('button').innerHTML='wow I changed';});</script>\n`
于 2020-01-02T08:07:20.567 回答