需要两次单击Javascript onclick才能运行功能 [英] Javascript onclick needs to be clicked twice for function to run
问题描述
需要双击Javascript onclick才能运行功能.我需要它在第一次单击时运行,这是我的问题.我已经在Google上搜索了2天,却没有找到有效或可以理解的答复.
Javascript onclick needs to be clicked twice for function to run. I need it to run on the first click, That is my problem. I've googled and searched for 2 days now without finding a reply that worked or that I understood.
可在此处找到javascript代码: http://enji.se/windows8/js/script.js
The code for the javascript can be found here: http://enji.se/windows8/js/script.js
以及我希望其运行的网站: http://enji.se/windows8/
And the site where I want it to work: http://enji.se/windows8/
这是我正在尝试制作的具有Windows 8外观的网站.它只能在Google Chrome和分辨率高于1265x820的显示器上正确显示,并且在分辨率高于1590x920的显示器上效果非常好
It's a Windows 8 looking website I'm trying to make. It will only display correctly on Google Chrome and on a resolution higher then 1265x820 and will be awesome on resolutions higher then 1590x920
预先感谢/enji
已解决
推荐答案
问题出在点击处理程序boxBegin
内-第一次单击时会收到click事件,并将其正确传递给您的方法,但是在boxBegin
内在box.style.display
值上切换行为-在IE9中,它最初是",它会触发您的关闭代码,而不是您想要的打开代码.
The problem is inside your click handler boxBegin
- the click event is received and passed to your method correctly on the first click, but inside boxBegin
you are switching behaviour on the value of box.style.display
- in IE9 this is initially "", which triggers your close code rather than the open code you want.
将box更改为:
function boxBegin() {
var box = document.getElementById('boxBegin');
if (!box.style.display || box.style.display == "none") {
box.style.display = "block";
}
else {
box.style.display = "none";
}
}
这篇关于需要两次单击Javascript onclick才能运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!