在公司常用的一些Js效果,记下来以后用的上。
input添加文字提示效果:
<input type="text" value="模糊型号查询" onfocus="if(value=='模糊型号查询') {value=''}" onblur="if (value=='') {value='模糊型号查询'}" name="keyword" size="30" />
<input type="text" value="联系人" onFocus="this.select();this.style.color='#000000'" onClick="if (this.value=='联系人'){this.value=''}" onblur="if(this.value ==''||this.value=='联系人'){this.value='联系人';this.style.color='#CCCCCC'}" /> |
经典的数字验证代码:
<script type="text/javascript">
function checkform(form){
var sortid=form.sortid.value;
if(sortid==null||trim(sortid)==""){
alert("请输入排列序号");
return false;
}
strTemp="0123456789";
for(i=0;i<sortid.length;i++){
if((strTemp.indexOf(sortid.charAt(i)))==-1){
alert("排列序号只能为数字");
return false;
}
}
return true;
}
function trim(s){
return s.replace(/^s*/,"").replace(/s*$/,"");
}
</script>
在超链接之前进行判断:
<a href="xxx.html"
onclick="{if(confirm('确定要超链接吗?')){return true;}return false;}">链接</a>