在firefox浏览器中未定义windows.event如何解决 [英] windows.event is undefined in firefox browser how to resolve
问题描述
大家好,
在这里,我使用以下脚本来验证手机和电子邮件,但是它在所有浏览器中都可以正常运行,但是Firefox期望出现错误"
hi to all,
Here i using this below script to validate mobile and email but it work in all browser expect firefox got error "
window.event is undefined
"
剧本:-
"
Script:-
function CheckMode() {
var ctr = document.getElementById('ctl00_cplhControlPanel_frmViewAdd_tablInsert_tabInsMain_drpModeofContactAdd');
var ctrMobile = document.getElementById('ctl00_cplhControlPanel_frmViewAdd_tablInsert_tabInsMain_txtMobileAdd');
var ctrEmail = document.getElementById('ctl00_cplhControlPanel_frmViewAdd_tablInsert_tabInsMain_txtEmailIdAdd');
var txt = ctr.value;
var Mobile = ctrMobile.value;
var Email = ctrEmail.value;
if (txt == "1") {
if (Mobile == "") {
alert("Enter Mobile Number");
Page_IsValid = false;
return window.event.returnValue = false;
}
}
else if (txt == "2") {
if (Email == "") {
alert("Enter Email Id");
Page_IsValid = false;
return window.event.returnValue = false;
}
}
else {
Page_IsValid = true;
}
}
按钮:-
button:-
<asp:Button ID="InsertButton" TabIndex="17" CssClass="savebutton1231" EnableTheming="false"
runat="server" CausesValidation="True" CommandName="Insert" SkinID="skinBtnSave"
OnClientClick="CheckMode();" OnClick="InsertButton_Click"></asp:Button>
请帮助我完成所有浏览器中的工作.谢谢.
Kindly help me for this task i need to work in all browser.Thanks in advance.
推荐答案
window.event
在Firefox中不存在.尝试将参数e
添加到CheckMode函数,然后将OnClientClick
更改为CheckMode(event);
.这会将事件传递给CheckMode
.
如果传递给CheckMode
的参数e
未定义但window.event没有定义,您还可以在函数中添加一行e = e || window.event;
给e
值window.event
.
window.event
does not exist in Firefox. Try adding a parametere
to your CheckMode function, then changeOnClientClick
toCheckMode(event);
. That will pass the event toCheckMode
.
You can also add a linee = e || window.event;
to your function that givese
the value ofwindow.event
, in case the parametere
passed toCheckMode
is undefined but window.event is not.
function CheckMode(e) {
e = e || window.event;
...
<asp:Button ID="InsertButton" TabIndex="17" CssClass="savebutton1231" EnableTheming="false" runat="server" CausesValidation="True" CommandName="Insert" SkinID="skinBtnSave" OnClientClick="CheckMode(event);" OnClick="InsertButton_Click"></asp:Button>
您永远不要使用此属性;它在标准中不存在.请参阅: https://developer.mozilla.org/en-US/docs/Web/API /Window [ ^ ].
此属性可能仅在IE中存在,并且反映了概念上的技术滥用现象:通过外部上下文传递事件信息,因此仅在调用事件时才定义此对象.使用这种不可靠的技术的整个想法是严重错误的,但是谁能说在IE中实现的任何内容都是可以信任的呢?
正确的方法是将事件对象作为处理程序的第一个参数传递.这是最简单的示例:
You should never use this property; it does not exist in standard. Please see: https://developer.mozilla.org/en-US/docs/Web/API/Window[^].
This property probably only exist in IE, and it reflects the big conceptual technology abuse: passing the event information through outer context, so this object is only defined when the event is invoked. The whole idea to use such unreliable technique is badly wrong, but who tells that anything implemented in IE can be trusted?
The correct approach is to pass event object as the first argument of a handler. This is the simplest example:
<button onclick="myHandler(event)">Some Button</button> <!-- use this exact name, "event" -->
在JavaScript中,您可能有
In JavaScript, you may have
function myHandler(eventInstance) {
// use eventInstance here
}
使用click
,您没有任何基本信息,但是使用鼠标或键盘事件,您可以获得鼠标坐标或键数据等.请参阅: https://developer.mozilla.org/en-US/docs/Web/API /Event [ ^ ].
尝试使用正确的标准技术,切勿购买IE挑衅. :-)
With click
, you don''t have any essential information, but with mouse or keyboard events you can get mouse coordinates, or key data, and so on. Please see: https://developer.mozilla.org/en-US/docs/Web/API/Event[^].
Try to use correct standard techniques, never buy IE provocations. :-)
这篇关于在firefox浏览器中未定义windows.event如何解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!