chrome firefox中JS回车登录
2016-03-08 18:34
471 查看
<script type="text/javascript">
//回车登陆
function myBrowser() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isOpera = userAgent.indexOf("Opera") > -1;
if (isOpera) {
return "Opera"
}; //判断是否Opera浏览器
if (userAgent.indexOf("Firefox") > -1) {
return "FF";
} //判断是否Firefox浏览器
if (userAgent.indexOf("Chrome") > -1) {
return "Chrome";
}
if (userAgent.indexOf("Safari") > -1) {
return "Safari";
} //判断是否Safari浏览器
if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
return "IE";
}; //判断是否IE浏览器
}
//以下是调用上面的函数
var mb = myBrowser();
if ("IE" == mb) {
//回车时,默认是登陆
function on_return() {
if (window.event.keyCode == 13) {
if (document.all('into') != null) {
document.all('into').click();
}
}
}
}
if ("FF" == mb) {
document.onkeydown = function (event) {
e = event ? event : (window.event ? window.event : null);
if (e.keyCode == 13) {
if (document.all('into') != null) {
document.all('into').click();
}
}
}
}
if ("Chrome" == mb) {
//回车时,默认是登陆
function on_return() {
if (window.event.keyCode == 13) {
if (document.all('into') != null) {
document.all('into').click();
}
}
}
} else {
function on_return() {
if (window.event.keyCode == 13) {
if (document.all('into') != null) {
document.all('into').click();
}
}
}
}
</script>
<body onkeydown="on_return();">
<a href="/" id="into" onclick="login()">登录</a>
</body>
//回车登陆
function myBrowser() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isOpera = userAgent.indexOf("Opera") > -1;
if (isOpera) {
return "Opera"
}; //判断是否Opera浏览器
if (userAgent.indexOf("Firefox") > -1) {
return "FF";
} //判断是否Firefox浏览器
if (userAgent.indexOf("Chrome") > -1) {
return "Chrome";
}
if (userAgent.indexOf("Safari") > -1) {
return "Safari";
} //判断是否Safari浏览器
if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
return "IE";
}; //判断是否IE浏览器
}
//以下是调用上面的函数
var mb = myBrowser();
if ("IE" == mb) {
//回车时,默认是登陆
function on_return() {
if (window.event.keyCode == 13) {
if (document.all('into') != null) {
document.all('into').click();
}
}
}
}
if ("FF" == mb) {
document.onkeydown = function (event) {
e = event ? event : (window.event ? window.event : null);
if (e.keyCode == 13) {
if (document.all('into') != null) {
document.all('into').click();
}
}
}
}
if ("Chrome" == mb) {
//回车时,默认是登陆
function on_return() {
if (window.event.keyCode == 13) {
if (document.all('into') != null) {
document.all('into').click();
}
}
}
} else {
function on_return() {
if (window.event.keyCode == 13) {
if (document.all('into') != null) {
document.all('into').click();
}
}
}
}
</script>
<body onkeydown="on_return();">
<a href="/" id="into" onclick="login()">登录</a>
</body>
相关文章推荐
- JS浏览器兼容问题
- 编写跨浏览器的javascript代码必备[js多浏览器兼容写法]
- ECMAScript和JavaScript的关系
- Servlet 和Jsp的生命周期
- JSONP原理分析
- JavaScript中操作表格
- js ES6 对字符的操作注意事项
- JS实现的图片循环播放浏览框
- js 时间函数 及相关运算大全
- JS判断客户端是手机还是PC
- 实现实体类和json类之间的相互转换
- pyhton标准库 json
- js DOM节点的创建、插入、删除、查找、替换方法学习与总结
- thinkjs crud练习
- 0x05: post 守护进程(deamon) json 任务调度
- javascript对结点的增、删、改
- ArcGIS API for JavaScript开发笔记(一)GP模型创建及服务发布
- js如何判断一个对象是不是Array
- js中Math方法的小技巧
- JavaScript 解析json例子