??xml version="1.0" encoding="utf-8" standalone="yes"?> 比如gender?昄P其余昄奻I我们可以q么写: 但是不是昑־太麻烦了Q其实我们这里就可以使用EL表达式中的三元运符了,上面可以化ؓQ?/p>
${gender eq 0?"?:"?} q样是不是简l了很多Q在JSTL和EL处理非A即B的时候,三元q算W简单了许多?/p>
转蝲h明:观测?/a> » JSP中EL表达式三元运符的?/a> function openAndClose(myelement) { }
]]>
<c:when test="${gender eq 0}">?span style="color: rgb(0,0,128); font-weight: bold"></c:when>
<c:otherwise>?span style="color: rgb(0,0,128); font-weight: bold"></c:otherwise>
</c:choose>
]]>
]]>
alert(myelement.attributes["value"].value );
]]>
http://www.miniui.com/demo/#src=messagebox.html
]]>
var t = document.getElementById("myT");
for ( var i = 0; i < 3; i++) {
var r = t.insertRow();
for ( var j = 0; j < 2; j++) {
var c = r.insertCell();
if (j == 0) {
c.innerHTML = "姓名Q?+i+","+j;
} else {
c.innerHTML = "<input type='text' name='n' />";
}
}
}
t.setAttribute('border', '1');
}
function deleteTable() {
var objTable = document.getElementById("myT");
objTable.setAttribute('border', '0');
for ( var i = 0; i <= objTable.rows.length+1; i++) {
objTable.deleteRow(0);
}
}
//通过l纬度坐标来初始化地?br />var point = new BMap.Point(125.4360909,43.78802888999); // 创徏点坐?nbsp;
map.centerAndZoom(point, 15); // 初始化地图,讄中心点坐标和地图U别
//通过城市名称来初始化地图
//map.centerAndZoom("长春");
var marker = new BMap.Marker(point); // 创徏标注
map.addOverlay(marker);
map.enableScrollWheelZoom(); // 开启鼠标滚轮羃?nbsp;
map.enableKeyboard(); // 开启键盘控?nbsp;
map.enableContinuousZoom(); // 开启连l羃放效?nbsp;
map.enableInertialDragging(); // 开启惯性拖拽效?
map.addControl(new BMap.NavigationControl()); //d标准地图控g(左上角的攑֤~小左右拖拽控g)
map.addControl(new BMap.ScaleControl()); //d比例控?左下角显C的比例控?
map.addControl(new BMap.OverviewMapControl()); // ~略图控?br />map.addControl(new BMap.MapTypeControl()); //// 仅当讄城市信息ӞMapTypeControl的切换功能才能可用map.setCurrentCity("北京");
map.setCurrentCity("吉林?);
//d自定义控?/p>
// 定义一个控件类Q即function
function ZoomControl(){
// 讄默认停靠位置和偏U量
this.defaultAnchor = BMAP_ANCHOR_TOP_LEFT;
this.defaultOffset = new BMap.Size(50, 10);
}
// 通过JavaScript的prototype属性承于BMap.Control
ZoomControl.prototype = new BMap.Control();
// 自定义控件必d现initializeҎQƈ且将控g的DOM元素q回
// 在本Ҏ中创Zdiv元素作ؓ控g的容器,q将其添加到地图容器?nbsp;
ZoomControl.prototype.initialize = function(map){
// 创徏一个DOM元素
var div = document.createElement("div");
// d文字说明
div.appendChild(document.createTextNode("长春工业大学人文信息学院"));
// 讄样式
div.style.cursor = "pointer";
div.style.border = "1px solid gray";
div.style.backgroundColor = "white";
// l定事gQ点Mơ放大两U?nbsp;
div.onclick = function(e){
alert("长春工业大学人文信息学院");
}
// dDOM元素到地图中
map.getContainer().appendChild(div);
// DOM元素q回
return div;
}
// 创徏控g实例
var myZoomCtrl = new ZoomControl();
// d到地囑ֽ?nbsp;
map.addControl(myZoomCtrl);
//d信息H口
var opts = {
width : 200, // 信息H口宽度
height: 70, // 信息H口高度
title : "长春工业大学人文信息学院" // 信息H口标题
}
var infoWindow = new BMap.InfoWindow("您好Q欢q来到长春工业大学h文信息学?, opts); // 创徏信息H口对象
map.openInfoWindow(infoWindow, map.getCenter()); // 打开信息H口
</script>
</body>
</html>
q行效果?br />
transitional.dtd">
<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScriptq河游戏</title>
<style type="text/css">
#content{width:800px;height:600px;border:1px #333333 solid;overflow:hidden;}
#A{width:120px;height:600px;float:left;background:#996633;}
#B{width:560px;height:600px;float:left;background:#0099FF;}
#river{width:560px;height:450px;}
#operator{width:560px;height:150px;background:#99CCFF;overflow:hidden;}
#C{width:120px;height:600px;float:right;background:#996633;}
#people{width:100px;height:20px;border:2px #000000 solid;margin:10px auto;text-
align:center;cursor:pointer;padding:10px 0px;}
#ship{width:200px;height:20px;border:1px #CC3300
solid;background:#663300;position:relative;top:150px;left:0px;text-align:center;padding:10px 0px;cursor:pointer;}
#btns{width:560px;height:40px;margin-top:10px;}
#btn{width:60px;height:20px;border:1px #000000 solid;background:#FFFFCC;text-align:center;padding:10px
0px;cursor:pointer;float:left;margin-left:210px;display:inline;}
#new{width:60px;height:20px;border:1px #000000 solid;background:#FFFFCC;text-align:center;padding:10px
0px;cursor:pointer;float:left;margin-left:10px;display:inline;}
#rule{width:560px;height:100px;margin-top:10px;font-family:宋体;font-size:12px;color:#666666;line-
height:16px;text-align:center;}
</style>
<script type="text/javascript">
var direction; //A to C:true ; C to A:false
var people=new Array(9);
var s2Able; //判断?是否有h
var s1Able; //判断?是否有h
var pInShip1; //哪个人在??br />var pInShip2; //哪个人在??br />function init(){
var peopleA=document.getElementById("A").getElementsByTagName("div");
var ships=document.getElementsByName("ship");
var peopleC=document.getElementById("C").getElementsByTagName("div");
var moveBtn=document.getElementById("btn");
var newBtn=document.getElementById("new");
for(var i=0,len=peopleC.length;i<len;i++){
peopleC[i].style.visibility="hidden";
}
s1Able=true;
s2Able=true;
direction=true;
for (var i=0;i<9;i++)
{
people[i]=true;
}
//注册事g
var len=peopleA.length;
for(var j=0;j<len;j++){
(function(m){
peopleA[m].onclick = function(){
if(direction)
selectPeople(this,m+1);
};
peopleC[m].onclick = function(){
if(!direction)
selectPeople(this,m+10+1);
};
})(j);
}
ships[0].onclick=function(){
quitShip(this,pInShip1);
s1Able=true;
pInShip1=0;
};
ships[1].onclick=function(){
quitShip(this,pInShip2);
s2Able=true;
pInShip2=0;
};
moveBtn.onclick=function(){
move();
};
newBtn.onclick=function(){
window.location = window.location;
};
}
function selectPeople(obj,move_num){
var ships=document.getElementsByName("ship");
if(s1Able){
ships[0].innerHTML=obj.innerHTML;
obj.style.visibility="hidden";
s1Able=false;
pInShip1=move_num;
if(move_num>10)
people[move_num-10]=!people[move_num-10];
else
people[move_num]=!people[move_num];
}
else if(s2Able){
ships[1].innerHTML=obj.innerHTML;
obj.style.visibility="hidden";
s2Able=false;
pInShip2=move_num;
if(move_num>10)
people[move_num-10]=!people[move_num-10];
else
people[move_num]=!people[move_num];
}
// 烈火E?liehuo.net Ƣ迎复制,拒绝恶意采集 liehuoQnet
else{
alert("船上最多两个hQ已?");
}
}
function quitShip(obj,quitId){
if(obj.innerHTML != ""){
var peopleA=document.getElementById("A").getElementsByTagName("div");
var peopleC=document.getElementById("C").getElementsByTagName("div");
if(quitId > 10){
peopleC[quitId-10-1].style.visibility="visible";
people[quitId-10]=!people[quitId-10];
}
else{
peopleA[quitId-1].style.visibility="visible";
people[quitId]=!people[quitId];
}
obj.innerHTML="";
}
}
function motherCheck(){
if(people[1]==people[5])
{
if(people[4]!=people[1])
{
alert("妈妈打儿?");
return false;
}
}
if(people[1]==people[6])
{
if(people[4]!=people[1])
{
alert("妈妈打儿?");
return false;
}
}
return true;
}
function fatherCheck(){
if(people[4]==people[2])
{
if(people[1]!=people[4])
{
alert("爸爸打女?");
return false;
}
}
if(people[4]==people[3])
{
if(people[1]!=people[4])
{
alert("爸爸打女?");
return false;
}
}
return true;
}
function policeCheck(){
if(people[7]!=people[8])
{
for(var i=1;i<8;i++)
{
if(people[8]==people[i])
{
alert("犯h伤h");
return false;
}
}
}
return true;
}
function atoc(peopleId){
var peopleC=document.getElementById("C").getElementsByTagName("div");
var ships=document.getElementsByName("ship");
var tempId;
if(peopleId > 10){
tempId = peopleId - 10 -1;
}
else
tempId = peopleId - 1;
if(tempId >= 0)
peopleC[tempId].style.visibility="visible";
for(var i=0,len=ships.length;i<len;i++){
ships[i].style.left = "360px";
ships[i].innerHTML = "";
}
}
function ctoa(peopleId){
var peopleA=document.getElementById("A").getElementsByTagName("div");
var ships=document.getElementsByName("ship");
var tempId;
if(peopleId > 10){
tempId = peopleId - 10 -1;
}
else
tempId = peopleId - 1;
if(tempId >= 0)
peopleA[tempId].style.visibility="visible";
for(var i=0,len=ships.length;i<len;i++){
ships[i].style.left = "0px";
ships[i].innerHTML = "";
}
}
function move(){
if(pInShip1==1 || pInShip1==4 || pInShip1==7 ||
pInShip1==11 || pInShip1==14 || pInShip1==17 ||
pInShip2==1 || pInShip2==4 || pInShip2==7 ||
pInShip2==11 || pInShip2==14 || pInShip2==17
) //开动船只的人只能是爸爸妈妈或者是警察
{
if (motherCheck()&& fatherCheck() && policeCheck())
{
if(direction)
{
atoc(pInShip1);
atoc(pInShip2);
direction=false;
}
else
{
ctoa(pInShip1);
ctoa(pInShip2);
direction=true;
}
s1Able=s2Able=true;
pInShip1=pInShip2=0;
var peopleC=document.getElementById("C").getElementsByTagName("div");
var result = true;
for(var i=0,len=peopleC.length;i<len;i++){
if(peopleC[i].style.visibility=="hidden"){
result = false;
break;
}
}
if(result){
alert("你真厉害Q?);
window.location = window.location;
}
}
}
else
alert("只有妈妈、爸爸和警察能撑船!");
}
window.onload = function(){
init();
};
</script>
</head>
<body>
<div id="content">
<div id="A">
<div id="people" name="people">妈妈</div>
<div id="people" name="people">奛_1</div>
<div id="people" name="people">奛_2</div>
<div id="people" name="people">爸爸</div>
<div id="people" name="people">儿子1</div>
<div id="people" name="people">儿子2</div>
<div id="people" name="people">警察</div>
<div id="people" name="people">土匪</div>
</div>
<div id="B">
<div id="river">
<div id="ship" name="ship"></div>
<div id="ship" name="ship"></div>
</div>
<div id="operator">
<div id="btns">
<div id="btn">Ud</div>
<div id="new">重玩</div>
</div>
<div id="rule">
游戏规则Q?lt;br />
1.无论大h、小孩,每次最多只能承载两人?.只有爸爸、妈妈、警察可以驾舏V?lt;br />
3.妈妈看到爸爸d儿子打儿子?.爸爸看到妈妈d奛_打女ѝ?lt;br />
5.土匪d警察会伤宛_人?.先选择人物Q然后点?Ud"按钮?lt;br />
7.Udq程中若出现提示Q说明违反上q规则?br /></div>
</div>
</div>
<div id="C">
<div id="people" name="people">妈妈</div>
<div id="people" name="people">奛_1</div>
<div id="people" name="people">奛_2</div>
<div id="people" name="people">爸爸</div>
<div id="people" name="people">儿子1</div>
<div id="people" name="people">儿子2</div>
<div id="people" name="people">警察</div>
<div id="people" name="people">土匪</div>
</div>
</div>
</body>
</html>
var selectChar = new Array(2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z');
for(var i=0;i<codeLength;i++) {
var charIndex = Math.floor(Math.random()*32);
code +=selectChar[charIndex];
}
if(code.length != codeLength){
createCode();
}
checkCode.value = code;
}
function validate () {
var inputCode = document.getElementById("input1").value.toUpperCase();
if(inputCode.length <=0) {
alert("误入验证码Q?);
return false;
}
else if(inputCode != code ){
alert("验证码输入错误!");
createCode();
return false;
}
else {
alert("OK");
return true;
}
}
</script>
</head>
<body onload="createCode();">
<input type="text" id="input1" />
<input type="text" id="checkCode" class="code" style="width: 55px" /> <a href="#" onclick="createCode()">看不清楚</a><br /><br />
<center><input id="Button1" onclick="validate();" type="button" value="定" /></center>
<script></script>
</body>
</html>
function WeekDay(date){
var theDate;
if (typeof(date)=="string"){theDate = new Date(date.split("-")[0],date.split("-")[1],date.split("-")[2]);}
if (typeof(date)=="object"){theDate = date}
return theDate.getDay();
}
function HS_calender(){
var lis = "";
var style = "";
style +="<style type='text/css'>";
style +=".calender { width:170px; height:auto; font-size:12px; margin-right:14px; background:url(calenderbg.gif) no-repeat right center #fff; border:1px solid #397EAE; padding:1px}";
style +=".calender ul {list-style-type:none; margin:0; padding:0;}";
style +=".calender .day { background-color:#EDF5FF; height:20px;}";
style +=".calender .day li,.calender .date li{ float:left; width:14%; height:20px; line-height:20px; text-align:center}";
style +=".calender li a { text-decoration:none; font-family:Tahoma; font-size:11px; color:#333}";
style +=".calender li a:hover { color:#f30; text-decoration:underline}";
style +=".calender li a.hasArticle {font-weight:bold; color:#f60 !important}";
style +=".lastMonthDate, .nextMonthDate {color:#bbb;font-size:11px}";
style +=".selectThisYear a, .selectThisMonth a{text-decoration:none; margin:0 2px; color:#000; font-weight:bold}";
style +=".calender .LastMonth, .calender .NextMonth{ text-decoration:none; color:#000; font-size:18px; font-weight:bold; line-height:16px;}";
style +=".calender .LastMonth { float:left;}";
style +=".calender .NextMonth { float:right;}";
style +=".calenderBody {clear:both}";
style +=".calenderTitle {text-align:center;height:20px; line-height:20px; clear:both}";
style +=".today { background-color:#ffffaa;border:1px solid #f60; padding:2px}";
style +=".today a { color:#f30; }";
style +=".calenderBottom {clear:both; border-top:1px solid #ddd; padding: 3px 0; text-align:left}";
style +=".calenderBottom a {text-decoration:none; margin:2px !important; font-weight:bold; color:#000}";
style +=".calenderBottom a.closeCalender{float:right}";
style +=".closeCalenderBox {float:right; border:1px solid #000; background:#fff; font-size:9px; width:11px; height:11px; line-height:11px; text-align:center;overflow:hidden; font-weight:normal !important}";
style +="</style>";
var now;
if (typeof(arguments[0])=="string"){
selectDate = arguments[0].split("-");
var year = selectDate[0];
var month = parseInt(selectDate[1])-1+"";
var date = selectDate[2];
now = new Date(year,month,date);
}else if (typeof(arguments[0])=="object"){
now = arguments[0];
}
var lastMonthEndDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+now.getMonth()+"-01").getDate();
var lastMonthDate = WeekDay(now.getFullYear()+"-"+now.getMonth()+"-01");
var thisMonthLastDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+(parseInt(now.getMonth())+1).toString()+"-01");
var thisMonthEndDate = thisMonthLastDate.getDate();
var thisMonthEndDay = thisMonthLastDate.getDay();
var todayObj = new Date();
today = todayObj.getFullYear()+"-"+todayObj.getMonth()+"-"+todayObj.getDate();
for (i=0; i<lastMonthDate; i++){ // Last Month's Date
lis = "<li class='lastMonthDate'>"+lastMonthEndDate+"</li>" + lis;
lastMonthEndDate--;
}
for (i=1; i<=thisMonthEndDate; i++){ // Current Month's Date
if(today == now.getFullYear()+"-"+now.getMonth()+"-"+i){
var todayString = now.getFullYear()+"-"+(parseInt(now.getMonth())+1).toString()+"-"+i;
lis += "<li><a href=javascript:void(0) class='today' onclick='_selectThisDay(this)' title='"+now.getFullYear()+"-"+(parseInt(now.getMonth())+1)+"-"+i+"'>"+i+"</a></li>";
}else{
lis += "<li><a href=javascript:void(0) onclick='_selectThisDay(this)' title='"+now.getFullYear()+"-"+(parseInt(now.getMonth())+1)+"-"+i+"'>"+i+"</a></li>";
}
}
var j=1;
for (i=thisMonthEndDay; i<6; i++){ // Next Month's Date
lis += "<li class='nextMonthDate'>"+j+"</li>";
j++;
}
lis += style;
var CalenderTitle = "<a href='javascript:void(0)' class='NextMonth' onclick=HS_calender(HS_DateAdd('m',1,'"+now.getFullYear()+"-"+now.getMonth()+"-"+now.getDate()+"'),this) title='Next Month'>»</a>";
CalenderTitle += "<a href='javascript:void(0)' class='LastMonth' onclick=HS_calender(HS_DateAdd('m',-1,'"+now.getFullYear()+"-"+now.getMonth()+"-"+now.getDate()+"'),this) title='Previous Month'>«</a>";
CalenderTitle += "<span class='selectThisYear'><a href='javascript:void(0)' onclick='CalenderselectYear(this)' title='Click here to select other year' >"+now.getFullYear()+"</a></span>q?lt;span class='selectThisMonth'><a href='javascript:void(0)' onclick='CalenderselectMonth(this)' title='Click here to select other month'>"+(parseInt(now.getMonth())+1).toString()+"</a></span>?;
if (arguments.length>1){
arguments[1].parentNode.parentNode.getElementsByTagName("ul")[1].innerHTML = lis;
arguments[1].parentNode.innerHTML = CalenderTitle;
}else{
var CalenderBox = style+"<div class='calender'><div class='calenderTitle'>"+CalenderTitle+"</div><div class='calenderBody'><ul class='day'><li>?lt;/li><li>一</li><li>?lt;/li><li>?lt;/li><li>?lt;/li><li>?lt;/li><li>?lt;/li></ul><ul class='date' id='thisMonthDate'>"+lis+"</ul></div><div class='calenderBottom'><a href='javascript:void(0)' class='closeCalender' onclick='closeCalender(this)'>×</a><span><span><a href=javascript:void(0) onclick='_selectThisDay(this)' title='"+todayString+"'>Today</a></span></span></div></div>";
return CalenderBox;
}
}
function _selectThisDay(d){
var boxObj = d.parentNode.parentNode.parentNode.parentNode.parentNode;
boxObj.targetObj.value = d.title;
boxObj.parentNode.removeChild(boxObj);
}
function closeCalender(d){
var boxObj = d.parentNode.parentNode.parentNode;
boxObj.parentNode.removeChild(boxObj);
}
function CalenderselectYear(obj){
var opt = "";
var thisYear = obj.innerHTML;
for (i=1970; i<=2020; i++){
if (i==thisYear){
opt += "<option value="+i+" selected>"+i+"</option>";
}else{
opt += "<option value="+i+">"+i+"</option>";
}
}
opt = "<select onblur='selectThisYear(this)' onchange='selectThisYear(this)' style='font-size:11px'>"+opt+"</select>";
obj.parentNode.innerHTML = opt;
}
function selectThisYear(obj){
HS_calender(obj.value+"-"+obj.parentNode.parentNode.getElementsByTagName("span")[1].getElementsByTagName("a")[0].innerHTML+"-1",obj.parentNode);
}
function CalenderselectMonth(obj){
var opt = "";
var thisMonth = obj.innerHTML;
for (i=1; i<=12; i++){
if (i==thisMonth){
opt += "<option value="+i+" selected>"+i+"</option>";
}else{
opt += "<option value="+i+">"+i+"</option>";
}
}
opt = "<select onblur='selectThisMonth(this)' onchange='selectThisMonth(this)' style='font-size:11px'>"+opt+"</select>";
obj.parentNode.innerHTML = opt;
}
function selectThisMonth(obj){
HS_calender(obj.parentNode.parentNode.getElementsByTagName("span")[0].getElementsByTagName("a")[0].innerHTML+"-"+obj.value+"-1",obj.parentNode);
}
function HS_setDate(inputObj){
var calenderObj = document.createElement("span");
calenderObj.innerHTML = HS_calender(new Date());
calenderObj.style.position = "absolute";
calenderObj.targetObj = inputObj;
inputObj.parentNode.insertBefore(calenderObj,inputObj.nextSibling);
}
function onclick_check2() {
var popup_width = 400;
var popup_height = 350;
var popup_left = (screen.width - popup_width) / 2;
var popup_top = (screen.height - popup_height) / 2;
var popup_scrollbars = "no";
var popup_property = "width=" + popup_width;
var popup_property = popup_property + ",height=" + popup_height;
var popup_property = popup_property + ",left=" + popup_left;
var popup_property = popup_property + ",top=" + popup_top;
var popup_property = popup_property + ",scrollbars=" + popup_scrollbars;
window.open('<%=request.getContextPath()%>/commu/pop_post.jsp','zipcode',popup_property);
}
/*
目录:
1:js 字符串长度限制、判断字W长?、js限制输入、限制不能输入、textarea 长度限制
2.:js判断汉字、判断是否汉?、只能输入汉?/p>
3:js判断是否输入英文、只能输入英?/p>
4:js只能输入数字,判断数字、验证数字、检数字、判断是否ؓ数字、只能输入数?/p>
5:只能输入英文字符和数?/p>
6: js email验证 、js 判断email 、信?邮箱格式验证
7:js字符qo,屏蔽关键?/p>
8:js密码验证、判断密?
2.1: js 不ؓI、ؓI或不是对象 、判断ؓI?、判断不为空
2.2:比较两个表单的值是否相?/p>
2.3:表单只能为数字和"_",
2.4:表单输入数?长度限定
2.5:中文/英文/数字/邮g地址合法性判?/p>
2.6:限定表单不能输入的字符
2.7表单的自W控?/p>
1. 查一D字W串是否全由数字l成
2. 怎么判断是否是字W?/p>
3. 怎么判断是否含有汉字
4. 邮箱格式验证
5. 数字格式验证
6. 电话L格式验证
7. 判断输入是否Z文的函数
8. l合的判断用戯入的合法性的函数
9. 判断密码是否输入一?/p>
10. 判断用户名是否ؓ数字字母下滑U?/p>
2.8:form文本域的通用校验函数
*/
1. 长度限制
<script>
function test()
{
if(document.a.b.value.length>50)
{
alert("不能过50个字W!");
document.a.b.focus();
return false;
}
}
</script>
<form name=a onsubmit="return test()">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea>
<input type="submit" name="Submit" value="check">
</form>
2. 只能是汉?
<input onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')">
3." 只能是英?/p>
<script language=javascript>
function onlyEng()
{
if(!(event.keyCode>=65&&event.keyCode<=90))
event.returnvalue=false;
}
</script>
<input onkeydown="onlyEng();">
4. 只能是数?/p>
<script language=javascript>
function onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)))
//考虑键盘上的数字键
event.returnvalue=false;
}
</script>
<input onkeydown="onlyNum();">
5. 只能是英文字W和数字
<input onkeyup="value="/oblog/value.replace(/[\W]/g,"'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
6. 验证油箱格式
<SCRIPT LANGUAGE=javascript RUNAT=Server>
function isEmail(strEmail) {
if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
alert("oh");
}
</SCRIPT>
<input type=text onblur=isEmail(this.value)>
7. 屏蔽关键?q里屏蔽***?***)
<script language="javascript1.2">
function test() {
if((a.b.value.indexOf ("***") == 0)||(a.b.value.indexOf ("****") == 0)){
alert(":)");
a.b.focus();
return false;}
}
</script>
<form name=a onsubmit="return test()">
<input type=text name=b>
<input type="submit" name="Submit" value="check">
</form>
8. 两次输入密码是否相同
<FORM METHOD=POST ACTION="">
<input type="password" id="input1">
<input type="password" id="input2">
<input type="button" value="test" onclick="check()">
</FORM>
<script>
function check()
{
with(document.all){
if(input1.value!=input2.value)
{
alert("false")
input1.value = "";
input2.value = "";
}
else document.forms[0].submit();
}
}
</script>
够了?:)
屏蔽右键 很酷
oncontextmenu="return false" ondragstart="return false" onselectstart="return false"
加在body?/p>
?/p>
2.1 表单不能ؓI?/p>
<script language="javascript">
<!--
function CheckForm()
{
if (document.form.name.value.length == 0) {
alert("误入您姓名!");
document.form.name.focus();
return false;
}
return true;
}
-->
</script>
2.2 比较两个表单的值是否相?/p>
<script language="javascript">
<!--
function CheckForm()
if (document.form.PWD.value != document.form.PWD_Again.value) {
alert("您两ơ输入的密码不一P请重新输?");
document.ADDUser.PWD.focus();
return false;
}
return true;
}
-->
</script>
2.3 表单只能ؓ数字?_",用于电话/银行帐号验证?可扩展到域名注册{?/p>
<script language="javascript">
<!--
function isNumber(String)
{
var Letters = "1234567890-"; //可以自己增加可输入?/p>
var i;
var c;
if(String.charAt( 0 )=='-')
return false;
if( String.charAt( String.length - 1 ) == '-' )
return false;
for( i = 0; i < String.length; i ++ )
{
c = String.charAt( i );
if (Letters.indexOf( c ) < 0)
return false;
}
return true;
}
function CheckForm()
{
if(! isNumber(document.form.TEL.value)) {
alert("您的电话L不合法!");
document.form.TEL.focus();
return false;
}
return true;
}
-->
</script>
2.4 表单输入数?长度限定
<script language="javascript">
<!--
function CheckForm()
{
if (document.form.count.value > 100 || document.form.count.value < 1)
{
alert("输入数g能小于零大于100!");
document.form.count.focus();
return false;
}
if (document.form.MESSAGE.value.length<10)
{
alert("输入文字于10!");
document.form.MESSAGE.focus();
return false;
}
return true;
}
//-->
</script>
2.5 中文/英文/数字/邮g地址合法性判?/p>
<SCRIPT LANGUAGE="javascript">
<!--
function isEnglish(name) //英文值检?/p>
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charCodeAt(i) > 128)
return false;
}
return true;
}
function isChinese(name) //中文值检?/p>
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charCodeAt(i) > 128)
return true;
}
return false;
}
function isMail(name) // E-mail值检?/p>
{
if(! isEnglish(name))
return false;
i = name.indexOf(" at ");
j = name dot lastIndexOf(" at ");
if(i == -1)
return false;
if(i != j)
return false;
if(i == name dot length)
return false;
return true;
}
function isNumber(name) //数值检?/p>
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charAt(i) < "0" || name.charAt(i) > "9")
return false;
}
return true;
}
function CheckForm()
{
if(! isMail(form.Email.value)) {
alert("您的电子邮g不合法!");
form.Email.focus();
return false;
}
if(! isEnglish(form.name.value)) {
alert("英文名不合法Q?);
form.name.focus();
return false;
}
if(! isChinese(form.cnname.value)) {
alert("中文名不合法Q?);
form.cnname.focus();
return false;
}
if(! isNumber(form.PublicZipCode.value)) {
alert("邮政~码不合法!");
form.PublicZipCode.focus();
return false;
}
return true;
}
//-->
</SCRIPT>
2.6 限定表单不能输入的字符
<script language="javascript">
<!--
function contain(str,charset)// 字符串包含测试函?/p>
{
var i;
for(i=0;i<charset.length;i++)
if(str.indexOf(charset.charAt(i))>=0)
return true;
return false;
}
function CheckForm()
{
if ((contain(document.form.NAME.value, "%\(\)><")) || (contain(document.form.MESSAGE.value, "%\(\)><")))
{
alert("输入了非法字W?);
document.form.NAME.focus();
return false;
}
return true;
}
//-->
</script>
1. 查一D字W串是否全由数字l成
---------------------------------------
<script language="Javascript"><!--
function checkNum(str){return str.match(/\D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>
2. 怎么判断是否是字W?
---------------------------------------
if (/[^\x00-\xff]/g.test(s)) alert("含有汉字");
else alert("全是字符");
3. 怎么判断是否含有汉字
---------------------------------------
if (escape(str).indexOf("%u")!=-1) alert("含有汉字");
else alert("全是字符");
4. 邮箱格式验证
---------------------------------------
//函数名:chkemail
//功能介绍Q检查是否ؓEmail Address
//参数说明Q要查的字符?
//q回|0Q不?1Q是
function chkemail(a)
{ var i=a.length;
var temp = a.indexOf('@');
var tempd = a.indexOf('.');
if (temp > 1) {
if ((i-temp) > 3){
if ((i-tempd)>0){
return 1;
}
}
}
return 0;
}
5. 数字格式验证
---------------------------------------
//函数名:fucCheckNUM
//功能介绍Q检查是否ؓ数字
//参数说明Q要查的数字
//q回|1为是数字Q?Z是数?
function fucCheckNUM(NUM)
{
var i,j,strTemp;
strTemp="0123456789";
if ( NUM.length== 0)
return 0
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//说明有字W不是数?
return 0;
}
}
//说明是数?
return 1;
}
6. 电话L格式验证
---------------------------------------
//函数名:fucCheckTEL
//功能介绍Q检查是否ؓ电话L
//参数说明Q要查的字符?
//q回|1为是合法Q?Z合法
function fucCheckTEL(TEL)
{
var i,j,strTemp;
strTemp="0123456789-()# ";
for (i=0;i<TEL.length;i++)
{
j=strTemp.indexOf(TEL.charAt(i));
if (j==-1)
{
//说明有字W不合法
return 0;
}
}
//说明合法
return 1;
}
7. 判断输入是否Z文的函数
---------------------------------------
function ischinese(s){
var ret=true;
for(var i=0;i<s.length;i++)
ret=ret && (s.charCodeAt(i)>=10000);
return ret;
}
8. l合的判断用戯入的合法性的函数
---------------------------------------
<script language="javascript">
//限制输入字符的位数开?
//m是用戯入,n是要限制的位?
function issmall(m,n)
{
if ((m<n) && (m>0))
{
return(false);
}
else
{return(true);}
}
9. 判断密码是否输入一?
---------------------------------------
function issame(str1,str2)
{
if (str1==str2)
{return(true);}
else
{return(false);}
}
10. 判断用户名是否ؓ数字字母下滑U?
---------------------------------------
function notchinese(str){
var reg=/[^A-Za-z0-9_]/g
if (reg.test(str)){
return (false);
}else{
return(true); }
}
2.8. form文本域的通用校验函数
---------------------------------------
作用Q检所有必非I的input文本Q比如姓名,账号Q邮件地址{等?/p>
该校验现在只针对文本域,如果要针对form里面的其他域对象Q可以改变判断条件?/p>
使用ҎQ在要检的文本域中加入title文字。文字是在提CZ息,你要提示l用L该字D늚中文名。比如要用户名
html如下<input name="txt_1" title="姓名">,当然Q最好用可视化工h如dreamweaver什么的来编辑域?/p>
如果要检数字类型数据的话,再把域的idl一为sz.
javascript判断日期cd比较ȝQ所以就没有做日期类型校验的E序?高手可以补充?/p>
E序比较草,只是提供一个思\。抛砖引玉! Q)
哦,对了Q函数调用方法:< form onsubmit="return dovalidate()">
function dovalidate()
{
fm=document.forms[0] //只检一个form,如果是多个可以改变判断条?/p>
for(i=0;i<fm.length;i++)
{
//判断条ӞҎcd不同可以修改
if(fm[i].tagName.toUpperCase()=="INPUT" &&fm[i].type.toUpperCase()=="TEXT" && (fm[i].title!=""))
if(fm[i].value="/blog/="")//
{
str_warn1=fm[i].title+"不能为空!";
alert(str_warn1);
fm[i].focus();
return false;
}
if(fm[i].id.toUpperCase()=="SZ")//数字校验
{
if(isNaN(fm[i].value))
{ str_warn2=fm[i].title+"格式不对";
alert(str_warn2);
fm[i].focus();
return false;
}
}
}
return true;
}