我有一个点击事件,我的动作导航到某个网址,然后显示/隐藏一个按钮是相关联的。我使用的是这样的:Jquery-如何处理事件作为参数点击功能
ViewManager.js
$("#btn").on("click", function(event){
window.location.href= '#test.html';
}
后,我打开这个网页,我有一个按钮,我需要表现取决于target.id隐藏(在这种情况下是。 btn
)。如果btn
是目标ID,我还隐藏按钮i显示按钮,类似如下:
account.js
if (event.target.id == 'btn'){
$('#submit-account-detail').css('display', 'none');
else {
$('#submit-account-detail').css('display', 'block');
}
现在的问题是,镀铬处理的全球盛会完美,但Firefox抛出错误:
ReferenceError: event is not defined
在我导航到不同的URL之前,我将事件作为参数传递。由于Firefox不能全局处理事件,它会引发错误。我尝试查找源代码,并且他们建议将事件作为参数传递给click事件(已完成)。但在页面导航之后,如何使事件可见?
编辑-------------------
我的确在ViewManager.js脚本是这样的:$("#btn").on("click", function(event){ targetId = window.event; window.location.href= '#test.html'; }
,然后我测试条件在account.js脚本:
if (targetId && targetId === 'btn'){
$('#submit-account-detail').css('display', 'none');}
它工作正常时,它已经定义了目标ID,而是抛出一个ReferenceError: targetId is not defined
当它targetId != 'btn'
...我是个宣布以错误的方式变种?
您的全球“事件”声明在哪里?您向我们展示的是一个函数参数,它是该函数的本地*。它决不可用于在不同的脚本文件中编码。 – Bergi 2014-10-05 23:32:50
如何以及在哪里可以申报一个?会这样:window.event =''?? – user1234 2014-10-05 23:37:43
您是否正在导航到不同的_page_或当前页面中的元素/定位点?如果它是一个不同的页面,你不能通过一个JS变量来做到这一点,因为即使是全局变量在当前页面中也只是“活着”的。如果它在当前页面内导航,为什么不能在原始点击处理程序中显示/隐藏按钮? – nnnnnn 2014-10-05 23:38:38