首先新建两个文件,文件名分别为:mail.html、mail.php,放在同一目录下。
mail.html文件内容如下:
1 <html>
2 <head>
3 <meta http-equiv="content-type" content="text/html;charset=utf-8">
4 </head>
5 <body>
6 <form action="" method="post" name="form1" id="form1">
7 <table border="1" width="100%">
8 <tr><td height="30">
9 请选择:
10 <select name="Card_Choice" id="Card_Choice" onChange="valideMail(this)">
11
12 <option id="s1" value="无">无</option>
13
14 <option id="s2" value="123">123</option>
15
16 <option id="s3" value="abc">abc</option>
17
18 <option id="s4" value="34dfd@">34dfd@</option>
19
20 </select><span id="show"></span>
21
22 </td></tr>
23
24 </table>
25
26 </form>
27
28 </body>
29
30 </html>
31
32 <script language="javascript">
33
34 var xmlHttp;
35
36 function valideMail(obj) {
37
38 //var email = document.getElementById("eMail");
39
40 var url = "mail.php?email=" + obj.value;
41
42 if (window.ActiveXObject) {
43
44 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
45
46 } else if (window.XMLHttpRequest) {
47
48 xmlHttp = new XMLHttpRequest();
49
50 }
51
52 xmlHttp.onreadystatechange = callBack;
53
54 xmlHttp.open(‘GET’, url, true);
55
56 xmlHttp.send(null);
57
58 }
59
60 function callBack() {
61
62 if (xmlHttp.readyState == 4) {
63
64 if (xmlHttp.status == 200) {
65
66 document.getElementById("show").innerHTML = "show:" + xmlHttp.responseText;
67
68 }
69
70 }
71
72 }
73
74 </script>
mail.php文件内容如下:
1 <?php
2
3 $email = $_GET["email"];
4
5 if ($email == "") {
6
7 $email = "rrrrrrrrrrrrrrrrrr !";
8
9 }
10
11 echo ($email);
12
13 exit(0);
14
15 ?>