我有一个使用事件监听器(点击)移动它的导航,然后我有一个“开始”按钮,禁用导航,以便进行一些自动化。我的问题是当你加载页面时,单击“开始”按钮,导航事件处理程序将删除它应该的事件。但是当我重新加载页面时,点击导航,在我点击“开始”之前,“开始”按钮将不再起作用 - 它甚至根本没有发射(通过一些警报测试)
导航代码:
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
}