//uses Ajax to load the data dictionary, generating select//parameter 1: Data dictionary type (DICT_TYPE_CODE)//Parameter 2: Put down the selected tag id//parameter 3: When generating the drop-down, the Name property value of the Select tag//Parameter 4: When a echo is required, select which Optionfunction loadselect (Typecode,positionid, Selectname,selectedid) {//1 Create a Select object, specify the Name property var $select = $ ("<select name=" +selectname+ "></select>") //2 add hint Option $select.append ($ ("<option value= >---Select---</option>");//3 use jquery's Ajax method to access background action$. Post ("${pagecontext.request.contextpath}/basedictaction", {Dict_type_code:typecode}, function (data) {//Traversal//4 Returns a JSON array object that iterates over its $.each (data, function (I, JSON) {//each traversal creates an option object var $option = $ ("<option value= '" +json[' dict_id ']+ ' > ' +json[' dict_item_name "]+" </option> "); if (json[' dict_id ' = = Selectedid) {//Determine if it needs to be echoed, if necessary to make it selected $option.attr ("Selected", "Selected");} And added to the Select Object $select.append ($option); }); }, "JSON");//5 the assembled select object into the page at the specified location $ ("#" +positionid). Append ($select);}
function Loaduserroleselect (typeurl,positionid,selectname,sid,selectedid) {
Create a Select
var $select = $ ("<select name=" +selectname+ "id=" +sid+ "></select>");
$select. Append ($ ("<option value=" >---Please select---</option> "));
$.ajax ({
"Async": true,
"Type": "Post",
"url": Typeurl,
"Success": function (data) {
$.each (Data,function (I,json) {
var $option = $ ("<option value=" "+json.id+" > "+json.rolename+" </option> ");
$select. Append ($option);
if (json[' userrole '] = = Selectedid) {
Determine if it needs to be echoed if necessary to make it selected
$option. attr ("Selected", "Selected");
}
})
},
"DataType": "JSON"
});
$ ("#" +positionid). Append ($select);
}
<script type= "Text/javascript" >
$ (function () {
Loaduserroleselect (
"${pagecontext.request.contextpath}/userrolelist.do",
"Selectbd", "Userrole", "Userrole", "${user.userrole}");
});
</script>
Use AJAX to load a data dictionary, generate a Select