【发布时间】:2021-05-09 21:05:54
【问题描述】:
我正在尝试创建一个非常简单的网页,其中包含一个在 js 中运行此脚本的按钮。我有一个js文件和一个html文件。
//var button = document.querySelector("button")
//button.onclick = function() {
demo = function() {
const CambDict = require("camb-dict");
const dictionary = new CambDict.Dictionary();
let lexicon = ["Flâneur", "Shibboleth", "Farrow", "Bon viveur/vivant"]
let randLexicon = lexicon[Math.floor(Math.random() * lexicon.length)]
console.log(randLexicon)
dictionary.meaning(randLexicon)
.then(console.log)
.catch(console.error)
}
<!DOCTYPE html>
<html>
<head>
<title>Dictionary</title>
</head>
<body>
<h1>Simple Dictionary</h1>
<button onclick="myFunction()">New word</button>
<p id="demo"></p>
<script src="dictionary.js"> function myFunction() </script>
</body>
</html>
【问题讨论】:
标签: javascript html button onclick