我在javascript中有代码,它获取不同键的键码并将其设置为隐藏字段。 然后,服务器端代码操纵隐藏字段。我的代码是:
function TriggeredKey(e) {
e = e || window.event;
var keycode;
if (window.event){
keycode = event.which ? window.event.which : window.event.keyCode;
}
alert(keycode);
document.getElementById("<%=hdfkey.ClientID %>").value = keycode;
_dopostback();
}
此代码在Chrome中运行良好,但在Mozilla中运行不正常。有人可以帮我解决这个问题吗?
答案 0 :(得分:2)
function TriggeredKey(e) {
e = e || window.event;
var keycode;
if (window.event){
//this check fails in mozilla/
//so the variable keycode is undefined
keycode = event.which ? window.event.which : window.event.keyCode;
}
if(!keycode){keycode = e.which}
//solves the issue
alert(keycode);
document.getElementById("<%=hdfkey.ClientID %>").value = keycode;
_dopostback();
}