<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.error{
color: red;
}
</style>
</head>
<body>
<form id="f1" action="s5.html" method="POST">
<div><input name="n1" tex = "用戶名" type="text" /></div>
<div><input name="n2" tex = "密碼" type="password" /></div>
<div><input name="n3" tex = "郵箱" type="text" /></div>
<div><input name="n4" tex = "端口" type="text" /></div>
<div><input name="n5" tex = "IP" type="text" /></div>
<input type="submit" value="提交" />
<!--有時候網絡速度慢,圖片加載慢,所以會先加載圖片框然后就開始綁定事件-->
<!--<img src="...">-->
</form>
<script src="jquery.js"></script>
<script>
// 當頁面框架加載完畢后,自動執行
$(function(){
$.Login('#f1')
});
$(function(){
// 當頁面所有元素完全加載完畢后,執行
$(':submit').click(function () {
$('.error').remove();
var flag = true;
$('#f1').find('input[type="text"],input[type="password"]').each(function () {
var v = $(this).val();
var n = $(this).attr('tex');
if(v.length <= 0){
flag = false;
var tag = document.createElement('span');
tag.className = "error";
tag.innerHTML = n + "必填";
$(this).after(tag);
// return false;
}
});
return flag;
});
});
// $(':submit').click(function () {
// var v = $(this).prev().val();
// if(v.length > 0){
// return true;
// }else{
// alert('請輸入內容');
// return false
// }
// })
</script>
</body>
</html>