我想在用户单击网页上的某个元素时创建一些功能。一旦页面执行,回调函数就会执行。它只能在用户点击元素时执行。 这里是代码:尝试通过回调函数失败
<!DOCTYPE html>
<html>
<head>
<title>Javascript Test</title>
<script src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>
$("#clickMe").one('click', printThis("Hello All"));
function printThis(msg) {
console.log(msg);
}
</script>
</head>
<body>
<div id="clickMe">Click me!</div>
</body>
</html>
谢谢!
你的功能将离开得太早。也许它是与您的用户名。 – hugomg