简体   繁体   English

Opera重定向问题

[英]Opera redirect problem

Hi everyone i have a problem like this. 大家好,我有这样的问题。

For example im in http://localhost/Search.aspx I have 2 textboxes (txtUserName and txtPassword) in my page for login. 例如在http://localhost/Search.aspx中的 im,我的页面上有2个文本框(txtUserName和txtPassword)用于登录。 user can press enter key to call Login() method when any of these textboxes focused. 当这些文本框中的任何一个集中时,用户可以按Enter键来调用Login()方法。 I capture enter key like this 我这样捕获回车键

txtUserName.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {Login();return false;}} else {return true}; ");
txtPassword.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {Login();return false;}} else {return true}; ");

Its calling the Login() method, and After doing that method Opera redirects the page to my default page ( http://localhost/Default.aspx ) 它调用Login()方法,执行完该方法后,Opera将页面重定向到我的默认页面( http://localhost/Default.aspx

Other browsers is working as it should, in other words they are not redirect me to the default page. 其他浏览器正在正常运行,换句话说,它们没有将我重定向到默认页面。

Opera version 10.61 Opera版本10.61

Alright, so you're problem here is Opera (bless it) doesn't support the onKeyDown command very well - so you have to look at onKeyUp or onKeyPress instead. 好的,所以您遇到的问题是Opera(祝福它)不很好地支持onKeyDown命令-因此,您必须查看onKeyUponKeyPress There's a really handy HTML table on quirksmode explaining this. quirksmode上有一个非常方便的HTML表格来解释这一点。

Given you're only trying to trap a control key onKeyUp is probably your best bet. 鉴于您只是试图捕获控制键,所以onKeyUp可能是您最好的选择。 I've been forced to combine onKeyDown and onKeyPress in order to catch text input AND control keys (but since you want text input to work as normal you don't need to go this far). 我被迫结合使用onKeyDownonKeyPress来捕获文本输入和控制键(但由于您希望文本输入正常工作,因此您无需走得太远)。

It should be simply a matter of switching "onkeydown" to "onkeyup" in your example fragment. 只需在示例片段中将“ onkeydown”切换为“ onkeyup”即可。

There is, perhaps, a question of why you'd be doing the above. 也许还有一个问题,为什么要执行上述操作。 I don't know what Login() does, but building a form with 3 parts (input-text, input-password, and input-submit button) will -by default- submit the form when enter is pressed in either of the input boxes, you could just add an onSubmit event to the form calling Login(); 我不知道Login()作用,但是构建一个包含3个部分(输入文本,输入密码和输入提交按钮)的表单,默认情况下,当在任一输入中按下Enter键时,都会提交表单框,您可以将onSubmit事件添加到调用Login();的表单中Login();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM