Struts Validator Framework provides an easy-to-use mechanism for performing client-side validation. It's very useful to validate some fields on the client-side before sending the data to the server for processing. By this way we can ensure that the data send to the server is valid. Performing validations on the client-side save the user a round trip time to the server.
For each validation routine defined in the validation-rules.xml file Struts provides an optional JavaScript code that can run on the client-side to perform the same validation that takes place on the server side.
Let's take a login application for our example. Our LoginForm extends DynaValidatorForm.
1.
2.
3.
4.
The following validations are defined in the validation.xml file.
01.
02.
03.
04.
05.
06.
07.
08.
09. minlength
10. 6
11.
12.
13.
To enable client-side validation you have to place the Struts HTML Tag Librar ......
function
Check_FileType(str)
{
var
pos
=
str.lastIndexOf(
"
.
"
);
var
lastname
=
str.substring(pos,str.length) //´Ë´¦Îļþºó׺ÃûÒ²¿ÉÓÃÊý×鷽ʽ»ñµÃstr.split(".")
if
(lastname.toLowerCase()
!=
"
.jpg
"
&&
lastname.toLowerCase()
!=
"
.gif
"
)
{
alert(
"
ÄúÉÏ´«µÄÎļþÀàÐÍΪ
"
+
lastname
+
"
£¬Í¼Æ¬±ØÐëΪ.jpg,.gifÀàÐÍ
"
);
document.myform.pic.focus();
return
false
;
}
else
{
return
true
;
}
}
http://www.cnblogs.com/SList/archive/2005/11/09/272164.html
......
ÓÃÒ»¸öÕý²à±í´ïʽÔÚjavascriptÖÐÑéÖ¤¾ÍÊÇ¿©!
<script language='javascript'>
function chkMail(){
if(document.form1.email.value=''){
alert("ÇëÌîдÓÊÏ䵨ַ!");
document.form1.email.focus();
return false;
}
//¿ªÊ¼ÑéÖ¤
var email = document.form1.email.value;
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
chkFlag = pattern.test(email);
if(chkFlag){
return true;
}
else
{
alert("ÓÊÏ䵨ַµÄ¸ñʽ²»ÕýÈ·£¡");
document.form1.email.focus();
return false;
}
}
</script>
~~~~~~~~~~~~~~~~~~~~~~~Íê±Ï£¡
×î¼òµ¥µÄ¾ÍÒ»¾ä£º
if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test('email'))
{
alert('email²»ÕýÈ·');
}
----------------------------------------------------------------------------------------------------------------------------
js:
function isEmail(email)
{
invalidChars = " /;,:{}[]|*%$#!()`<>?";
if (email == "")
{
return false;
}
for (i=0; i< invalidChars.length; i++)
{
badChar = invalidChars.charAt(i)
if (email.inde ......
<script language="javascript">
function closeOpen(Panel) {
var test = document.getElementById('Panel');
if (test.style.display == "none") {
test.style.display = "";
}
else {
test.style.display = "none";
}
}
</script>
<input id="Button1" type="button" value="ÏÔʾÒþ²Øpanel" onclick="closeOpen('Panel1')" style="background-image: url('images/title_bg_hide.gif');" /> ......
LuaÓëjavascriptµÄ²îÒì - [luaѧϰ]
×ªÔØ
http://huazjxy.blogbus.com/logs/60132016.html
LuaÄ£ÄâÆ÷js·½°¸
1.Óï·¨¼¶Ä£Äâ
luaÓëjsÓïÑÔ²îÒì
1.1×¢ÊÍ
js Ϊ//,luaΪ--.
1.2±äÁ¿
jsÀûÓÃvalÀ´ÉùÃ÷È«¾Ö±äÁ¿²»´æÔÚ¾Ö²¿±äÁ¿£¬luaÔò²»ÐèÒªÖ±½Ó¶¨Î»ÔòΪȫ¾Ö±äÁ¿£¬localÉùÃ÷ÔòΪ¾Ö²¿±äÁ¿¡£
1.3ÔËËã·û
js
+ - * / % ++ --
= += -= *= /= %=
Ö§³Ö×Ö·û´® +
txt1 = "what a very";
txt2 = "nice day";
txt3 =txt1 " " +txt2;
´òÓ¡txt3Êä³ö½á¹ûΪ"what a very nice day".
¹æÔò:
°ÑÊý×ÖÓë×Ö·û´®Ïà¼Ó£¬½á¹û½«³ÉΪ×Ö·û´®.
lua
¶þÔª:+ - * / ^ %
Ò»Ôª:-(¸ººÅ)
lua×Ö·û´®Æ´½ÓΪ..
Èç"Hello ".."World"Æ´½Ó³ÉHello World
1.4¹ØÏµ²Ù×÷·û
js¹ØÏµ²Ù×÷·û
== ===(È«µÈ) != > < >= <=
lua¹ØÏµ²Ù×÷·û
< > <= >= == ~=(²»µÈÓÚ)
1.5 Âß¼ÔËËã·û
js
&& || !
lua
and or not
1.6 If ...ElseÓï¾ä
js Ààc
if else
lua
if then else
if then
elseif then
else
end
Ò»¶¨ÒªÓÐend
1.7 SwitchÓï¾ä
lua²»Ö§³ÖSwitch Óï¾ä
1.8 ÏûÏ¢¿ò
js
¾¯¸æ¿ò alert("Îı¾")
È·ÈÏ¿ò prompt("Îı¾","ĬÈÏÖµ")
......
×î½üһֱΪ´ËÍ·Í´£¬¹ÃÇÒ°ÑÎÒÄÜÏëµ½µÄ¶«Î÷¶¼Ð´³öÀ´°É¡£ÓÉÓÚ²»ÊǼòµ¥°ÑÒ³ÃæÉÏÊÖдµÄscriptתΪjavascriptÌí¼Ó£¬ÎÒÃÇÐèÒª¿¼ÂǵĶ«Î÷Ö÷ÒªÓÐÁ½¸ö£º¼ÓÔØµÄ˳Ðò£¬¼ÓÔØÇ°ºó½Å±¾µÄÔË×÷¡£
ÏÈ˵µÚÒ»¸ö£¬¼ÙÈçÎÒÃÇÒÑÓÐÒ»¼ÓÔØ»úÖÆÁË£¬Òª¼ÓÔØÒ»¸öÐÂÄ£¿é£¬µ±È»ÐÂÄ£¿éÊÇÔÚÁíÒ»¸öJSÎļþÖС£Õâʱ£¬ÎÒÃÇ¿ÉÒÔÃèÊöΪ£º
loader ---> a.js
Õâ¸ö¼ÓÔØ¹ý³Ì¿ÉÄÜ»á³öЩÒâÍ⣬Èç·þÎñÆ÷æµµÈÎÊÌ⣬ÔÝʱÎÞ·¨ÎªÎÒÃÇÉú³ÉJSÎļþ£¬ÎÒÃǾÍÐèÒªÔÙ´ÎÇëÇ󣬵«Ò²¿ÉÄÜÓÀÔ¶ÇëÇó²»ÉÏ£¬ÒòΪÄÇÊÇËÀÁ´£¬ºǫ́µÄÈËɵÁËÄÔ´ü£¬¸ÄÁ˵ØÖ·Ò²²»Í¨ÖªÉù£¬ÎÒÃÇÐèÒªÒ»¸ö½ØÖ¹ÆÚÏÞ¡£Õâʱ£¬ÎÒÃÇ¿ÉÒÔÃèÊöΪ£º
loader ---> a.js ---> a.js ---> .....----> timeout
Èç¹ûÄǸöÄ£¿éÒªÒÀÀµÓÚÆäËûÄ£¿éÄØ£¬ÄÇôÎҾͱØÐëÔÚ¼ÓÔØËü֮ǰ¼ÓÔØÆäËûÄ£¿éÁË¡£Õâʱ£¬ÎÒÃÇ¿ÉÒÔÃèÊöΪ£º
loader ---> b.js ---> a.js ---> .....----> timeout
µ«¼Ç¼ÕâЩÒÀÀµ¹ØÏµµÄÐÅÏ¢¿Ï¶¨ÔÚa.jsÉÏ£¬¶ø²»ÔÚloaderÉÏ£¬Í¨¹ýa.jsÎÒÃDzÅÄܵÃÖªb.js£¬»»ÑÔÖ®Òª×ñÑ×îÉÙ֪ʶÔÔò£¨Law of Demeter£©¡£
Õâ¸öÎÊÌâµÄ½â¾ö£¬MochiKitÐËÐíÄܸøÎÒÃÇһЩÁé¸Ð°É¡£
ÁíÒ»¸öÎÊÌâÊÇjavascriptÊǵ¥Ï̵߳쬶ø¼ÓÔØÐèÒªÒ»¸öʱ¼ä£¬²¢ÇÒͨ³£ÊÇÒì²½µÄ¡£µ±ÎÒÃÇÖ´ÐмÓÔØº¯Êýºó£¬¿ÉÄÜJSÒýÇæ»á¼ÌÐ ......