现在我正在使用 <body onload="function">
,它会根据关注的元素更改页面上的一些文本。它工作正常,但我需要我的网站在每次焦点更改时运行该功能(或者更好的是,每次单击页面的任何部分时)。
目前代码如下所示:
<body onload="changeText()">
<script>
function changeText(){
function here;
}
</script>
<p>This is where text changes based on the function</p>
谢谢!
最佳答案
您可以在文档上附加 onclick 事件。 jsfiddle
document.onclick = function(){
// your code
//alert("clicked");
}
如果你想改变焦点然后使用
window.onfocus = function(){
// your code
//alert("focus");
}
关于javascript - 如何通过单击页面运行 JavaScript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12845680/