我使用 HTML5 属性来显示有关文本框验证的警报消息。它在 chrome 上运行良好,但在 IE8 上运行良好。我也添加了html5shiv.js
,但确实没有解决... PFB我的代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"></script>
<![endif]-->
<script src="html5shiv.js"></script>
<script>
$(document).ready(function () {
var element = document.getElementById("name");
element.oninvalid = function (e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity("The field 'From' cannot be left blank");
}
};
})
</script>
</head>
<body>
<form>
<label>From:<input name="username" id="name" type="text" placeholder="Eg. Town Hall" required="true" autofocus="true"/></label>
<input type="submit" value="go" />
</form>
</body>
</html>