验证:失去焦点弹出对话框value===========================================================
<input type="text" class="inputh" value="" id="name" name="name" οnblur="f_check(this)"/>
----------------------------
<script>
function f_check(obj){
var reg=/^[\w]{2,}$/;
if(!obj.value.match(reg)){
alert("用户名格式不正确!");
}
</script>
表单提交时逐项验证===========================================================
<form id="loginForm" method="post" name="loginform" action="UserServlet?action=login" onsubmit = "return check()">
<input class="text" type="text" id="userId" name="username" />
<input class="text" type="password" id="password" name="password" />
<div id="error"></div>
<input type="submit" name="submit" value="立即登录" />
</form>
----------------------------
<script type="text/javascript">
function check(){
var username=document.getElementById("username");
var password=document.getElementById("password");
var error =document.getElementById("error");
if(username.value==""){
error.innerHTML="<font color=\"red\">用户名不能为空!</font>";
username.focus();
return false;
}else if(password.value==""){
error.innerHTML="<font color=\"red\">密码不能为空!</font>";
password.focus();
return false;
}
return true;
}
</script>
表单提交自动正则验证各项,同时锁定任务栏document.getElementById===========================================================
<form action="UserServlet?opr=login" method="post" οnsubmit="return checks();">
<input type="text" class="inputh" value="" id="username" name="name" />
<input type="text" class="inputh" value="" id="password" name="password" />
<div id="error"></div>
<input name="" type="submit" value="登 录" />
<input id="register" name="" type="button" value="注 册" οnclick='javascript:location="register.jsp"' />
</form>
----------------------------
<script type="text/javascript">
function checks() {
var username = document.getElementById("username");
var password = document.getElementById("password");
var error = document.getElementById("error");
var reg = /^[\w]{3,10}$/;
if (username.value == "") {
error.innerHTML = "<font color=\"red\">用户名不能为空!</font>";
username.focus();
return false;
}
if (!(username.value.match(reg))) {
error.innerHTML = "<font color=\"red\">用户名格式不正确!用户名只能由字母数字下划线组成,不低于三位!</font>";
username.focus();
return false;
}
if (password.value == "") {
error.innerHTML = "<font color=\"red\">密码不能为空!</font>";
password.focus();
return false;
}
if (!(password.value.match(reg))) {
error.innerHTML = "<font color=\"red\">密码不能为空!密码只能由字母数字下划线组成,不低于三位!</font>";
username.focus();
return false;
}
return true;
}
</script>
点击后确定传递参数后操作===========================================================
<input οnclick="dele(${onegood.auctionid});"
type="submit" value="修改" class="spbg buttombg f14 sale-buttom" />
<input
type="submit" value="删除" class="spbg buttombg f14 sale-buttom" οnclick="abc(${onegood.auctionid});"/>
-----------------------
<script type="text/javascript">
function abc(x){
if(confirm("你真的确认要删除吗?请确认")){
location.href="goodservlet?opr=deletegood&gid="+x;
return true;
}
else{
return false;
}
};
function dele(x){
if(confirm("你真的确认要修改吗?请确认")){
location.href="goodservlet?opr=tochange&gid="+x;
return true;
}
else{
return false;
}
}
</script>
-----------------------------------
<dd class="dds">
<label>拍卖品图片:</label>
<div class="lf salebd"><img id="imgid" src="images/ad20.jpg" width="100" height="100" /></div>
<input name="pic" type="file" class="offset10 lf" οnchange="showPic()"/>
<div id="picid" class="lf red laba">请上传图片</div>
</dd>
----------------------------------
jq实现非空验证:空时显示提示,输入则不显示(id,name属性)value取值===========================================================
<dd >
<label>名称:</label>
<input type="text" οnblur="checkAuctionName()" name="auctionName" class="inputh lf" value="" />
<div id="nameid" class="lf red laba">名称不能为空</div>
</dd>
--------------------------------
function checkAuctionName(){
if($("auctionName").value==""){
$("nameid").style.display="block";
return false;
}else{
$("nameid").style.display="none";
return true;
}
}
-----------------------------
function checkStartPrice(){
if(($("startPrice").value=="")||(isNaN($("startPrice").value)==true)){
$("startPriceid").style.display="block";
return false;
}else{
$("startPriceid").style.display="none";
return true;
}
}
-------------------------form中跳转
function checkValue(){
if((checkAuctionName()&&checkStartPrice()&&checkUpset()&&checkStartTime()&&checkEndTime())==true){
if($("pic").value==""){
$("picid").style.display="block";
return false;
}else{
$("picid").style.display="none";
return true;
}
}
return false;
}
-----------------------------------
function showPic(){
$("imgid").src=$("pic").value;/*考虑到安全性和兼容性问题,发布拍卖品时,图片可以不显示*/
}
form表单上传图片后,在特定区域显示图片,利用表单的 onchange属性===========================================================
function showPic(){
$("imgid").src=$("pic").value;/*考虑到安全性和兼容性问题,发布拍卖品时,图片可以不显示*/
}
------------------------------
<dd class="dds">
<label>拍卖品图片:</label>
<div class="lf salebd"><img id="imgid" src="images/ad20.jpg" width="100" height="100" /></div>
<input name="pic" type="file" class="offset10 lf" οnchange="showPic()"/>
<div id="picid" class="lf red laba">请上传图片</div>
</dd>
===========================================================
===========================================================
===========================================================
常用js代码总结
最新推荐文章于 2022-10-18 17:18:16 发布