好用:
JS写上边
配配 excel、cvs类型文件
<script type="text/javascript">
function check(){
var textF = document.getElementById("textfield");
var cur = textF.value;
var reg = /\.(?:csv|xls|xlsx)$/i;
var filename=cur;
var index1=filename.lastIndexOf(".");
//alert(index1);
var index2=filename.length;
//alert(index2);
var postf=filename.substring(index1,index2);//后缀名
alert(postf);
if(reg.exec(postf)){
alert(" 上传成功")
}else{
alert(" 上传失败")
return false;
}
/*var textF = document.getElementById("textfield");
var cur = textF.value;
var reg = /(\.xls|\.xlsx|\.csv)/ig;
if(reg.test(cur)){
alert(" 上传成功")
}
else{
alert(" 上传失败")
return false;
}*/
}
</script>
</head>
<form id="form1" method="post" action="/DealWithForm1/" onsubmit="return check()">
<table>
<tr>
<td>first_name:</td>
<td><input name="firstname" type="text" id="firstname" /></td>
<td><label id="firstnameLabel"></label></td>
</tr>
<tr>
<td>last_name:</td>
<td><input name="lastname" type="text" id="lastname" /></td>
<td><label id="lastnameLabel"></label></td>
</tr>
</table>
<hr width="40%" align="left" />
<button type="submit">提交</button>
<button type="button" onclick="jump();">取消</button>
</form>
==============================
另一种,可以配合使用,点按钮或其它操作时改变action
<input type="submit" value="确认" id="filters" />
$("#filters").click(function () {
//choose_checked();
alert('here');
if($("#choose22").attr("checked")=="checked"){
alert('选择了');
$("#myform").submit();
}else{
alert('没选择');
return false;
}
});
==============================
1、
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post">
用户帐号
<input type=text name="userId" size="18" value="" >
<br>
登录密码
<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆" onclick="return check(this.form)">
</form>
2
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post" onsubmit="return check(this)">
用户帐号
<input type=text name="userId" size="18" value="" >
<br>
登录密码
<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆">
</form>
3
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("请输入登录密码!");
form.password.focus();
return false;
}
document.myform.submit();
}
</script>
<form action="login.do?act=login" name="myform" method="post">
用户帐号
<input type=text name="userId" size="18" value="" >
<br>
登录密码
<input type="password" name="password" size="19" value=""/>
<input type=button name="submit1" value="登陆" onclick="check(this.form)">
</form>