Js结合struts回显select代码示例

来源:互联网 发布:苹果电脑图片编辑软件 编辑:程序博客网 时间:2024/06/03 20:27
   // 初始化内容
   function createSelect(position_id,dict_type_code,selectedId){
        alert(selectedId);
          var $select =  $("<select></select>");
         $select.append("<option>---------请选择---------</option>");
         $("#"+position_id).append($select);
        
         $.post("${pageContext.request.contextPath}/BaseDictAction", { "dict_type_code": dict_type_code },
                   function(json){
             $.each( json, function(i, json){
                 var $option = $("<option>"+json["dict_item_name"]+"</option>");
                 if(json['dict_id'] == selectedId){
                    
                        //判断是否需要回显 ,如果需要使其被选中
                            $option.attr("selected","selected");
                        }
                 $select.append($option);
                });
                   }, "json");

    }


写之前明确需要知道的内容:1添加select的位置

                                                     2需要查询的内容

                                                     3回显内容如何确定