我有一个函数showText()
,它可以将表单文本框中的一些文本复制到其他地方的段落中。它通过以下方式调用:
document.getElementById("mybutton").onclick = showText;
如果我将 () 添加到 showText 的末尾,它将不起作用,我通过阅读类似的答案了解到这是调用函数的唯一方法。
稍后在脚本中它需要 () 才能工作:
window.addEventListener("keypress", function(e) {
var keycode = e.keyCode;
if (keycode == 13) {
showText();
}
}, false);
我不确定这里发生了什么。