我有一个文本领域:<代码><input category=“text”/>,我想在失去重点时加以验证。 如果意见不有效,我想防止重点转向下一个要素,或者说要把重点放在无效的投入上,直到其有效为止。
我如何利用 j和 Java?
I have tried with this code, but it doesn t work (jsFiddle):
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.6.2.min.js"></script>
<script>
$(function() {
$( .hello ).bind( focusout , function(e) {
if(!isValid($(this).val())) {
e.preventDefault();
$(this).foucus();
}
});
});
function isValid(str) {
if(str === "hello") {
return true;
} else {
return false;
}
}
</script>
</head>
<body>
Only valid content: <b>hello</b><br>
<input type="text" class="hello"/>
<button>Dummy</button>
</body>
</html>