if ( typeof(Worker) !== "undefined" ) {
alert("支持html5")
} else {
alert("不支持html5")
}
方法二:
if ( window.applicationCache ) {
alert("支持html5")
} else {
alert("不支持html5")
}
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
window.onload = function() {
var login = document.getElementById("login")
login.addEventListener("submit",function(event) {
var user = document.getElementsByName("user")[0]
var pwd = document.getElementsByName("pwd")[0]
if (user.value.length <= 0) {
alert("请输入账号!")
event.preventDefault()
return false
} else {
//逻辑判断
}
if (pwd.value.length <= 0) {
alert("请输入密码!")
event.preventDefault()
return false
} else {
//逻辑判断
}
})
}
</script>
</head>
<body>
<a href="#" class="注册">立即注册</a>
<div>
<form action="home.html" method="post" id="login">
<input name="user" class="用户名" type="text" placeholder="邮箱地址/幻国度ID">
<input name="pwd" class="密码" type="password" placeholder="密码">
<input type="submit" class="登录" value="登录">
</form>
</div>
</body>
</html>
不懂的可以问我
还有:用中文命名class的我就服你一个!【滑稽】
用JS来判断:
<script>function myBrowser() {
var userAgent = navigator.userAgent //取得浏览器的userAgent字符串
var isChrome = userAgent.indexOf("Chrome") > -1 //判断是否Chrome浏览器
var isOpera = userAgent.indexOf("Opera") > -1 //判断是否Opera浏览器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera //判断是否IE浏览器
var isFF = userAgent.indexOf("Firefox") > -1 //判断是否Firefox浏览器
var isSafari = userAgent.indexOf("Safari") > -1 //判断是否Safari浏览器
if (isIE) {
var IE5 = IE55 = IE6 = IE7 = IE8 = false
var reIE = new RegExp("MSIE (\\d+\\.\\d+)")
reIE.test(userAgent)
var fIEVersion = parseFloat(RegExp["$1"])
IE55 = fIEVersion == 5.5
IE6 = fIEVersion == 6.0
IE7 = fIEVersion == 7.0
IE8 = fIEVersion == 8.0
if (IE55) { return "IE55" }
else if (IE6) { return "IE6" }
else if (IE7) { return "IE7" }
else if (IE8) { return "IE8" }
}
else if (isFF) { return "FF" }
else if (isChrome) { return "Chrome" }
else if (isOpera) { return "Opera" }
else if (isSafari) { return "Safari" }
}
console.log(myBrowser()) //会输出你使用的浏览器类型
</script>