1.html interface
<form action=""Method="Get"> <divclass="Form-group"> <divclass="col-sm-3"> <labelclass="Control-label"> Group </label> </div> <divclass="col-sm-9"> <SelectId="GroupType"Name="Offsettype" class="Table"></Select> </div> </div> <divclass="formcontrols col-xs-2 col-sm-2"> <SelectName="shipment.startstation"Id="startstation"></Select> </div> <div><button id="Button"Type="Submit"title="Submit"> Submit </button></div> </form>
View Code
2.getJSON method
<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 ' > Please select </option>"); $.each (result.employees, function (i, field) {varName = encodeURI (Field.name,"Utf-8"); varresult ="<option value= '"+ Field.id +"' >"+ Field.name +"</option>"; $('#groupType'). Append (result); }); $("#startstation"). HTML ("<option value= '-1 ' > Please select </option>"); $.each (Result.goodscode, function (i, field) {varName = encodeURI (Field.name,"Utf-8"); varresult ="<option value= '"+ Field.id +"' >"+ Field.name +"</option>"; $('#startstation'). Append (result); }); $("#button"). Click (function () {//$ ("#groupType"). attr ("Data-options", "required:true");//Set property to required entry varGroupType = $ ("#groupType"). Val (); if(GroupType <=0) {alert ("when the document is OMS, the item type must be entered, please select"); return false; } }); });
View Code
3. The following is the JS suffix saved JSON resource file
Getjson get JSON file load drop-down box and dynamic validation than input