我有一个使用事件侦听器(单击)在其中移动的导航,然后我有一个禁用导航的“开始”按钮,以便发生一些自动化。我的问题是,当您加载页面时,单击“开始”按钮,导航事件处理程序会按预期删除事件。但是当我重新加载页面时,在我点击“开始”之前点击导航,之后“开始”按钮将不再起作用 - 它甚至根本不会触发(经过一些警报测试)
导航代码:
var hrNav = document.getElementById('hrNav');
var startButton = document.getElementById('startButton');
//Check to see if the user is on an iPad or iPhone
var isiPad = (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i)) != null;
//EVENT LISTENER FOR NAVIGATION
//If the user is on an iphone or ipad, use the touchstart event listener rather than click. Use click otherwise, or use onclick for IE users.
if (isiPad == true) {
hrNav.addEventListener('touchstart', highlight);
} else {
if(hrNav.addEventListener){
hrNav.addEventListener('click', highlight);
} else {
hrNav.attachEvent('on'+'click', highlight);
}
}
//EVENT LISTENER FOR START BUTTON
if (isiPad == true) {
startButton.addEventListener('touchstart', start);
} else {
if(startButton.addEventListener){
startButton.addEventListener('click', start);
} else {
startButton.attachEvent('on'+'click', start);
}
}
//Function for start button
function start(e) {
hrNav.removeEventListener('click', highlight);
}
//Function for navigation
function highlight(ev) {
//Do Stuff
}