选个你比较擅长的Javascript Framework吧。 Mootool ,Prototype ,Jquery 都行。 如果你不选也能做。比较麻烦。
我是用Jquery 的。 就大概大概给你个概念吧。
如果用过Jquery 请Skip Step 1 Step 2
step 1: 做个基本的Form 出来。
- <script language="javascript" src="jquery.js"></script>
- <form action=http://localhost/urproject method="post">
- <input type="text" name="someVal">
- </form>
复制代码note:记得加入 jquery.js
http://jquery.com/
这里能下载。
step2 :这个是初始Jquery
- <script language="javascript" src="jquery.js"></script>
- <script>
- $(function(){
- })
- </script>
- <form action=http://localhost/urproject method="post">
- <input type="text" name="someVal">
- </form>
复制代码step 3:加入 <p id="result"></p> 在你的Form下方 然后加入普通的<p></p> 作提示。
- <script language="javascript" src="jquery.js"></script>
- <script>
- $(function(){
- })
- </script>
- <form action="http://localhost/urproject" method="post">
- <input type="text" name="someVal">
- </form>
- <p>
- length should more than 10.
- </p>
- <p id="result">
- </p>
复制代码step 4: run 这个program看看。
- <script language="javascript" src="jquery.js"></script>
- <script>
- $(function(){
- $("input[name=someVal]").blur(function(){ // 当someVal onBlur 的当儿执行。
- if($(this).val().length < 10)$("#result").html("<font color='red'>Invalid input</font>");
- // $(this).val() 的意思是 someVal 的Value, 字数少过十就放出红色的字体,如果是多过10就青色。 这个你应该会。
- else $("#result").html("<font color='green'>Pass !</font>");
- // $("#result").html() 就是~innerHtml. 总之不管是怎样都会写入<p></p> tag之间。
- })
- })
- </script>
- <form action="http://localhost/urproject" method="post">
- <input type="text" name="someVal">
- </form>
- <p>
- length should more than 10.
- </p>
- <p id="result">
- </p>
复制代码OK~搞定。run 看看就明白了。 至于传入后台就太多了。很累了。要睡觉。
http://www.willjessup.com/sandbo ... /form_validate.html
给你参考个,这个是后台的validation , 通过Ajax 去后台然后 Validate 了return 回来。
http://speckyboy.com/2009/12/17/ ... es-and-tutorials-2/
这里也有很多教程。
如果不是你要的,可以演示下你要的效果吗?
最后~加油
献丑了。写得不好请多多原谅。em0012" />" />
[
本帖最后由 宅男-兜着走 于 2010-3-18 03:45 AM 编辑 ]