博客
关于我
给select赋值过程
阅读量:400 次
发布时间:2019-03-05

本文共 1563 字,大约阅读时间需要 5 分钟。

初始化省份选项

通过set_province()函数初始化省份选项:

function set_province() { for (var i in region) { province[i - 1] = new Option(region[i].name, region[i].name); }}

基于事件的初始化

在页面加载完成后,通过jQuery.each遍历所有select元素:

$(document).ready(function () { $("select").each(function () { var $ele = $(this); var str = "@Model.personalDatas.personalDataAddress"; var $value = str.split("|"); $ele.find("option[value='" + $value[0] + "']").attr("selected", "selected"); var index = $ele.find("option[value='" + $value[0] + "']").index(); var data_region = region[index + 1]; city.length = 1; for (var i in data_region['child']) { city[i] = new Option(data_region['child'][i].name, data_region['child'][i].name); } $ele.find("option[value='" + $value[1] + "']").attr("selected", "selected"); console.log(province.selectedIndex); var data_region1 = region[province.selectedIndex + 1]['child'][city.selectedIndex]['child']; zone.length = 1; for (var i in data_region1) { for (var j in data_region1[i]) { zone[j] = new Option(data_region1[i][j].name, data_region1[i][j].name); } } $ele.find("option[value='" + $value[2] + "']").attr("selected", "selected"); $("#address").val($value[3]); });});

功能说明

该代码主要完成以下功能:

  • 初始化省份选项
  • 根据用户选择的省份自动加载区域信息
  • 基于区域信息初始化城市和区的选项
  • 设置默认地址信息

转载地址:http://gitzz.baihongyu.com/

你可能感兴趣的文章
python+locust电商全流程性能测试
查看>>
Python函数运行的可执行文件的终端输出如何以一般方式静音?
查看>>
Python+Pytest+Allure+Git+Jenkins接口自动化框架
查看>>
python+pytest接口自动化 —— 参数关联
查看>>
python+pytest接口自动化 —— 参数关联
查看>>
Python+pytest接口自动化 —— 接口测试基础
查看>>
python+pytest接口自动化 —— 自动化用例编写思路 (使用pytest编写一个测试脚本)
查看>>
Python+pytest接口自动化之cookie绕过登录(保持登录状态)
查看>>
python+pytest接口自动化:接口测试
查看>>
Python+requests+unittest执行接口自动化测试详情
查看>>
Python+requests+unittest执行接口自动化测试详情
查看>>
python+requests+unittest执行自动化接口测试!
查看>>
Python+Requests编码识别Bug
查看>>
python函数编写_[零基础学python]传说中的函数编写条规
查看>>
Python+selenium —— UI自动化之鼠标操作
查看>>
python函数注释,参数后面加冒号:,函数后面的箭头→是什么?
查看>>
Python+Selenium+Threading进行兼容性测试
查看>>
Python+selenium+unittest的GUI自动化框架实现
查看>>
python函数拟合不规则曲线_Python计算&绘图——曲线拟合问题(转)
查看>>
python函数定义的基本格式_零基础学python-2.19 定义函数、调用函数与默认参数
查看>>