JS制作二级联动

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>设置</title>
  6. <style>
  7. .div {
  8. -webkit-box-sizing: border-box;
  9. -moz-box-sizing: border-box;
  10. box-sizing: border-box;
  11. font-size: 18px;
  12. border: 1px solid #e1e1e1;
  13. box-shadow: none;
  14. width: 100%;
  15. height: 36px;
  16. padding: 4px 6px;
  17. font-size: 14px;
  18. line-height: 20px;
  19. color: #555;
  20. -webkit-border-radius: 4px;
  21. -moz-border-radius: 4px;
  22. border-radius: 4px;
  23. vertical-align: middle;
  24. }
  25. select {
  26. border: none;
  27. /*清除select的边框样式*/
  28. outline: none;
  29. /*清除select聚焦时候的边框颜色*/
  30. width: 20%;
  31. /* 将select的宽高等于div的宽高*/
  32. height: 30px;
  33. line-height: 30px;
  34. //隐藏select的下拉图标
  35. appearance: none;
  36. -webkit-appearance: none;
  37. -moz-appearance: none;
  38. /*//通过padding-left的值让文字居中*/
  39. padding-left: 60px;
  40. }
  41. //使用伪类给select添加自己想用的图标
  42. div:after {
  43. content: "";
  44. width: 14px;
  45. height: 8px;
  46. background: url(img/xiala.png) no-repeat center;
  47. //通过定位将图标放在合适的位置
  48. position: absolute;
  49. right: 20px;
  50. top: 45%;
  51. //给自定义的图标实现点击下来功能
  52. pointer-events: none;
  53. }
  54. </style>
  55. <link href="css/demo.css" rel="stylesheet" type="text/css">
  56. <script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
  57. <!--Framework-->
  58. <script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
  59. <script src="js/jquery-ui.js" type="text/javascript"></script>
  60. <!--End Framework-->
  61. <script src="js/jquery.ffform.js" type="text/javascript"></script>
  62. <script src="js/setting_ajax.js" type="text/javascript"></script>
  63. <script type="text/javascript">
  64. function setting_click() {
  65. //alert("点击");
  66. var province = $("#province").val(); //收件人邮箱名
  67. var city = $("#city").val(); //收件人传输协议,数值
  68. var province2 = $("#province2").val(); //发件人邮箱名
  69. var city2 = $("#city2").val(); //发件人传输协议,数值
  70. var name = $("#name").val(); //发件人昵称
  71. var email = $("#email").val(); //收件人邮箱
  72. var email_port; //端口
  73. var email_agreement; //协议
  74. var d = parseInt(city);
  75. switch(d) {
  76. case 0:
  77. email_agreement = "pop3.sohu.com";
  78. email_port = "110";
  79. break;
  80. case 1:
  81. email_agreement = "pop.126.com";
  82. email_port = "110";
  83. break;
  84. case 2:
  85. email_agreement = "POP.139.com";
  86. email_port = "110";
  87. break;
  88. case 3:
  89. email_agreement = "pop.163.com";
  90. email_port = "110";
  91. break;
  92. case 4:
  93. email_agreement = "pop.qq.com";
  94. email_port = "110";
  95. break;
  96. case 5:
  97. email_agreement = "pop.exmail.qq.com";
  98. email_port = "995";
  99. break;
  100. case 6:
  101. email_agreement = "POP.foxmail.com";
  102. email_port = "110";
  103. break;
  104. case 7:
  105. email_agreement = "pop.china.com";
  106. email_port = "110";
  107. break;
  108. case 8:
  109. email_agreement = "pop.mail.yahoo.com";
  110. email_port = "995";
  111. break;
  112. case 9:
  113. email_agreement = "pop.mail.yahoo.com.cn";
  114. email_port = "995";
  115. break;
  116. }
  117. alert("收件人:_邮箱名称 : "+province+"_传输协议:"+email_agreement+"_端口:"+email_port);
  118. var email_port2; //端口
  119. var email_agreement2; //协议
  120. var d2 = parseInt(city2);
  121. switch(d2) {
  122. case 0:
  123. email_agreement2 = "smtp.sohu.com";
  124. email_port2 = "25";
  125. break;
  126. case 1:
  127. email_agreement2 = "smtp.126.com";
  128. email_port2 = "25";
  129. break;
  130. case 2:
  131. email_agreement2 = "smtp.139.com";
  132. email_port2 = "25";
  133. break;
  134. case 3:
  135. email_agreement2 = "smtp.163.com";
  136. email_port2 = "25";
  137. break;
  138. case 4:
  139. email_agreement2 = "smtp.qq.com";
  140. email_port2 = "25";
  141. break;
  142. case 5:
  143. email_agreement2 = "smtp.exmail.qq.com";
  144. email_port2 = "587"; //(SSL启用 端口:587/465)
  145. break;
  146. case 6:
  147. email_agreement2 = "smtp.foxmail.com";
  148. email_port2 = "25";
  149. break;
  150. case 7:
  151. email_agreement2 = "smtp.china.com";
  152. email_port2 = "25";
  153. break;
  154. case 8:
  155. email_agreement2 = "smtp.mail.yahoo.com";
  156. email_port2 = "587";
  157. break;
  158. case 9:
  159. email_agreement2 = "smtp.mail.yahoo.com.cn";
  160. email_port2 = "587";
  161. break;
  162. }
  163. alert("发件人:_邮箱名称 : "+province2+"_传输协议:"+email_agreement2+"_端口:"+email_port2);
  164. /* ajax请求 */
  165. $.ajax({
  166. url: "",
  167. type: "post",
  168. data: {
  169. "email_name": province, //收件人邮箱名
  170. "email_agreement": email_agreement, //收件人协议
  171. "email_port": email_port, //端口
  172. "email_name2": province2, //发件人邮箱名
  173. "email_agreement2": email_agreement2, //发件人协议
  174. "email_port2": email_port2, //端口
  175. "name": name, //发件人昵称
  176. "email": email //收件人邮箱
  177. },
  178. dataType: "json",
  179. success: function(data) {
  180. console.log(data);
  181. if(data == 1) {
  182. alert("提交成功!");
  183. }
  184. }
  185. });
  186. }
  187. </script>
  188. <script type="text/javascript">
  189. $(document).ready(function() {
  190. $('#form').ffform({
  191. animation: 'flip',
  192. submitButton: '#submit',
  193. validationIndicator: '#validation',
  194. errorIndicator: '#error',
  195. successIndicator: '#success',
  196. 'fields': [{
  197. 'id': 'name',
  198. required: true,
  199. requiredMsg: 'Name is required',
  200. type: 'alpha',
  201. validate: true,
  202. msg: 'Invalid Name'
  203. }, {
  204. 'id': 'email',
  205. required: true,
  206. requiredMsg: 'E-Mail is required',
  207. type: 'email',
  208. validate: true,
  209. msg: 'Invalid E-Mail Address'
  210. }, {
  211. 'id': 'phone',
  212. required: false,
  213. type: 'custom',
  214. validate: false,
  215. msg: 'Invalid Phone #'
  216. }, {
  217. 'id': 'message',
  218. required: false,
  219. type: 'text',
  220. validate: false,
  221. msg: ''
  222. }]
  223. });
  224. });
  225. </script>
  226. </head>
  227. <body style="">
  228. <center>
  229. <div style="margin:0 auto;padding: 30px;">
  230. <form name="form1" method="post" action="" style="width: 100%;">
  231. 收件人:
  232. <select name="province" id="province" onchange="changeSelect(this.selectedIndex)"></select>
  233. 协议:
  234. <select name="city" id="city"></select>
  235. 发件人:
  236. <select name="province2" id="province2" onchange="changeSelect2(this.selectedIndex)"></select>
  237. 协议:
  238. <select name="city2" id="city2"></select>
  239. </form>
  240. </div>
  241. </center>
  242. <section id="getintouch" class="bounceIn animated">
  243. <div class="container" style="border-bottom: 0;">
  244. <h1>
  245. <span>请输入</span>
  246. </h1>
  247. </div>
  248. <div class="container">
  249. <form class="contact" action="#" method="post" id="form">
  250. <div class="row clearfix">
  251. <div class="lbl">
  252. <label for="name">
  253. 发件人昵称 </label>
  254. </div>
  255. <div class="ctrl">
  256. <input type="text" id="name" name="name" data-required="true" data-validation="text" data-msg="Invalid Name" placeholder="Ex:昵称">
  257. </div>
  258. </div>
  259. <div class="row clearfix">
  260. <div class="lbl">
  261. <label for="email">
  262. 收件人邮箱</label>
  263. </div>
  264. <div class="ctrl">
  265. <input type="text" id="email" name="email" data-required="true" data-validation="email" data-msg="Invalid E-Mail" placeholder="Ex:邮箱的地址">
  266. </div>
  267. </div>
  268. <div class="row clearfix">
  269. <div class="span10 offset2">
  270. <input type="button" name="setting_button" id="setting_button" class="submit" value="Send Message" onclick="setting_click()">
  271. </div>
  272. </div>
  273. </form>
  274. <div id="success">
  275. Your E-Mail has been sent successfully!</div>
  276. <div id="error">
  277. Unable to send e-mail at the moment, please try later.</div>
  278. <div id="validation">
  279. </div>
  280. </div>
  281. </section>
  282. <script type="text/javascript">
  283. var arr_province = ["邮箱名称",
  284. "搜狐邮箱",
  285. "126邮箱",
  286. "139邮箱",
  287. "163邮箱",
  288. "QQ邮箱",
  289. "QQ企业邮箱",
  290. "Foxmail",
  291. "china.com",
  292. "yahoo.com",
  293. "yahoo.com.cn",
  294. ];
  295. var arr_city = [
  296. ["传输协议"],
  297. ["pop3.sohu.com"],
  298. ['pop.126.com'],
  299. ["POP.139.com"],
  300. ['pop.163.com'],
  301. ["pop.qq.com"],
  302. ['pop.exmail.qq.com'],
  303. ["POP.foxmail.com"],
  304. ['pop.china.com'],
  305. ["pop.mail.yahoo.com"],
  306. ['pop.mail.yahoo.com.cn']
  307. ];
  308. var arr_province2 = ["邮箱名称",
  309. "搜狐邮箱",
  310. "126邮箱",
  311. "139邮箱",
  312. "163邮箱",
  313. "QQ邮箱",
  314. "QQ企业邮箱",
  315. "Foxmail",
  316. "china.com",
  317. "yahoo.com",
  318. "yahoo.com.cn",
  319. ];
  320. var arr_city2 = [
  321. ["传输协议"],
  322. ["smtp.sohu.com"],
  323. ['smtp.126.com'],
  324. ["smtp.139.com"],
  325. ['smtp.163.com'],
  326. ["smtp.qq.com"],
  327. ['smtp.exmail.qq.com'],
  328. ["SMTP.foxmail.com"],
  329. ['smtp.china.com'],
  330. ["smtp.mail.yahoo.com"],
  331. ['smtp.mail.yahoo.com.cn']
  332. ];
  333. //网页加载完成,初始化菜单
  334. window.onload = init; //传入函数地址
  335. function init() {
  336. //首先获取对象
  337. var province = document.form1.province;
  338. var city = document.form1.city;
  339. var province2 = document.form1.province2;
  340. var city2 = document.form1.city2;
  341. //指定省份中<option>标记的个数
  342. province.length = arr_province.length;
  343. province2.length = arr_province2.length;
  344. //循环将数组中的数据写入<option>标记中
  345. for(var i = 0; i < arr_province.length; i++) {
  346. province.options[i].text = arr_province[i];
  347. province.options[i].value = arr_province[i];
  348. //province.options[i].value = i;
  349. province2.options[i].text = arr_province2[i];
  350. province2.options[i].value = arr_province2[i];
  351. }
  352. //修改省份列表的默认选择项
  353. var index = 0;
  354. province.selectedIndex = index;
  355. province2.selectedIndex = index;
  356. //指定城市中<option>标记的个数
  357. city.length = arr_city[index].length;
  358. city2.length = arr_city2[index].length;
  359. //循环将数组中的数据写入<option>标记中
  360. for(var j = 0; j < arr_city[index].length; j++) {
  361. city.options[j].text = arr_city[index][j];
  362. city.options[j].value = arr_city[index][j];
  363. city2.options[j].text = arr_city2[index][j];
  364. city2.options[j].value = arr_city2[index][j];
  365. }
  366. }
  367. function changeSelect(index) {
  368. //选择对象
  369. var city = document.form1.city;
  370. //修改省份列表的选择项
  371. province.selectedIndex = index;
  372. //指定城市中<option>标记的个数
  373. city.length = arr_city[index].length;
  374. //循环将数组中的数据写入<option>标记中
  375. for(var j = 0; j < arr_city[index].length; j++) {
  376. city.options[j].text = arr_city[index][j];
  377. //city.options[j].value = arr_city[index][j];
  378. city.options[j].value = j;
  379. }
  380. }
  381. function changeSelect2(index) {
  382. //选择对象
  383. var city = document.form1.city2;
  384. //修改省份列表的选择项
  385. province2.selectedIndex = index;
  386. //指定城市中<option>标记的个数
  387. city2.length = arr_city[index].length;
  388. //循环将数组中的数据写入<option>标记中
  389. for(var j = 0; j < arr_city[index].length; j++) {
  390. city2.options[j].text = arr_city[index][j];
  391. //city2.options[j].value = arr_city[index][j];
  392. city2.options[j].value = j;
  393. }
  394. }
  395. </script>
  396. </body>
  397. </html>

JS制作二级联动的更多相关文章

  1. js:二级联动示例

    联动原理 当用户点击省级的下拉选项,选择所在省,下一个下拉选项里的选项,则变成用户选择省下的所有市的信息,不会出现其它省市的信息. 省市数据 把省市数据,保存在js文件中,以json形式保存,以便读取 ...

  2. js实现二级联动下拉列表菜单

    二级联动下拉列表菜单的难点在于对后台返回的数据进行解析,不多逼逼,直接上代码 上图是后台返回的数据 实现代码如下: var deviceNotExist = true;//防止数据重复 if(data ...

  3. 原生js实现二级联动下拉列表菜单

    二级联动下拉列表菜单的难点在于对后台返回的数据进行解析,不多逼逼,直接上代码 上图是后台返回的数据 实现代码如下: var deviceNotExist = true;//防止数据重复 if(data ...

  4. js省市二级联动实例

    //动态创建省市二级联动<!DOCTYPE html><html lang="en"><head> <meta charset=" ...

  5. js 实现二级联动

    onchange 事件 <body> <select id="province" onchange="func1()"> <opt ...

  6. js省市二级联动

    html: <script src="js/city.js"></script> ...... <body> <div class=&qu ...

  7. js 省市二级联动

    <html> <head> <meta charset="UTF-8"> <title></title> </he ...

  8. 原生js二级联动

    今天说的这个是原生js的二级联动,在空白页面里动态添加并作出相对应的效果. 1 //创建两个下拉列表 select标签 是下拉列表 var sel = document.createElement(& ...

  9. 利用JS实现一个简单的二级联动菜单

    前几天在看js的相关内容,所以就简单写了一个二级联动菜单.分享一下. <!DOCTYPE html> <html lang="en"> <head&g ...

随机推荐

  1. java String 类特点

    String的设计是一个典型的单一模式 String str1="AAAA":String str2="AAAA": 这生成两个对象吗?不是.在内存中,这是同一 ...

  2. C# DotNetZip压缩单、多文件以及文件夹

    有些项目为了更好的用户体验,会把下载文件做成一个压缩的文件,直接下载,免得去一个个的点击下载文件.网上有很多压缩文件的方法,也有第三方的分装DLL文件,本文主要介绍DotNetZip压缩方法. Dot ...

  3. Python笔记(六)_函数

    函数一般是从第一行代码开始执行,结束于return语句.异常.或者函数所有语句执行完毕.一旦函数将控制权交还给调用者,就意味着全部结束.函数中做的所有工作以及保存在局部变量中的数据都将丢失.再次调用这 ...

  4. 哈希算法和字典类的定义,DataSet中数据遍历的几种方法

    哈希算法的基本操作: 1.  哈希表(HashTable)简述   在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似 ...

  5. Java程序的设计环境配置

    一.下载主要的开发工具 JDK的下载 www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Ecli ...

  6. Mybatis的分支选择和In循环

    Mybatis的分支选择: <choose> <when test="patientNo != null and patientNo != ''"> and ...

  7. docker--container的port映射

    使用nginx为例 先运行nginx [root@localhost ~]# docker run --name web -d nginx Unable to find image 'nginx:la ...

  8. [css]等高列的简单实现

    又碰到css等高布局的问题,发现以前没有总结,这里再把基本原理写一下吧. 1.负边距控制法. <div id="content"> <div class=&quo ...

  9. h5py库

    参考文献:http://docs.h5py.org/en/latest/high/dataset.html h5py文件存放数据集(dataset)和组(group). dataset类似数组类的数据 ...

  10. 用List和Map排序输出

    参考:java的treemap反序输出 int->string string->int java对象数组的概述 List import java.io.*; import java.uti ...