我只是试图制作一个按钮(id =“ clickme”)链接index.html和js / buttonexample.js。我看到了按钮,但是它不起作用。我在浏览器和android模拟器上都尝试过。
js / buttonexample.js
document.getElementById("clickme").addEventListener("click", msg());
function msg() {
alert("good");
}
index.html
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/buttonexample.js"></script>
<div><Button id = "clickme">click</Button></div>
参照Cordova: onclick event is calling before button click我也试过
document.getElementById("clickme").addEventListener("click", msg);
<Button id = "clickme">click</Button>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/buttonexample.js"></script>
将脚本上方的按钮放在mag之后,不带括号
document.getElementById("clickme").addEventListener("click", msg);
function msg() {
alert("good");
}