窗口 onload 和窗口 onfocus
window.onload = function() {
window.onfocus = alert('example');
}
我遇到了这个问题,有人可以帮忙吗? 我是 javascript 新手,希望能正常工作,但事实并非如此:)
我想在页面完全加载并处于活动状态时提醒“示例”一词,但不想提醒“示例”一词如果页面已完全加载但未处于活动状态 (onblur
)。 当用户回来时(onfocus
),然后提醒“example”。
window.onload = function() {
window.onfocus = alert('example');
}
I've met this problem, anyone can help?
I'm new at javascript and made this expecting to work properly, but it does not :)
I want to alert the word "example" when the page is fully loaded and active, but don't want to alert the word "example" if the page is fully loaded but not active (onblur
).
And when user comes back (onfocus
) then alert "example".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的代码立即调用
alert
函数,并将其返回值分配给onfocus
。您需要将
onfocus
设置为调用alert
的匿名函数:Your code calls the
alert
function immediately and assigns its return value toonfocus
.You need to set
onfocus
to an anonymous function that callsalert
:试试这个:
Try this:
这是您需要的 JavaScript。
Here is the javascript that you need.