1.html界面
<form action="" method="get"> <div class="form-group"> <div class="col-sm-3"> <label class="control-label">集团</label> </div> <div class="col-sm-9"> <select id="groupType" name="offsetType" class="table "></select> </div> </div> <div class="formControls col-xs-2 col-sm-2"> <select name="shipment.startstation" id="startstation"></select> </div> <div><button id="button" type="submit" title="提交">提交</button></div> </form>
2.getJSON方法
<script src="~/Scripts/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $.getJSON("/Scripts/Data_Json/JsonList.js", function (result) { $("#groupType").html("<option value=‘-1‘>请选择</option>"); $.each(result.employees, function (i, field) { var name = encodeURI(field.name, "utf-8"); var result = "<option value=‘" + field.id + "‘>" + field.name + "</option>"; $(‘#groupType‘).append(result); }); $("#startstation").html("<option value=‘-1‘>请选择</option>"); $.each(result.goodscode, function (i, field) { var name = encodeURI(field.name, "utf-8"); var result = "<option value=‘" + field.id + "‘>" + field.name + "</option>"; $(‘#startstation‘).append(result); }); $("#button").click(function () { //$("#groupType").attr("data-options", "required:true");//设置属性为必输入项 var groupType = $("#groupType").val(); if (groupType <= 0) { alert("当单据为OMS时,货品类型必须输入,请选择"); return false; } }); });
3.以下是js后缀保存的Json资源文件
原文地址:https://www.cnblogs.com/markli/p/9278869.html
时间: 2024-10-09 22:40:51