select关于表单提交的问题

来源:互联网 发布:企业海关数据免费查询 编辑:程序博客网 时间:2024/05/23 01:12

让select随表单一起提交需要满足两个条件:

   1.select需要有name属性(作为json数据的key值)

   2.select必须要在form内部

             提交内容为:如果option有value属性,则提交当前选中value属性的值,如果没有则会提交当前选择内容的具体内容


在处理一对多关系时,我们需要将select中的对应的option的值作为其内容(也就是外键的值)示例如下:


  function createSelect(select_name,position_id,dict_type_code,selectedId){
        
        var $select =  $("<select name="+select_name+" ></select>");
         
         $select.append("<option value=''>---------请选择---------</option>");
          
        
         $.post("${pageContext.request.contextPath}/BaseDictAction", { "dict_type_code": dict_type_code },
                   function(json){
             $.each( json, function(i, json){
                 var $option = $("<option value='"+json['dict_id']+"'>"+json['dict_item_name']+"</option>");
                 if(json['dict_id'] == selectedId){
                    
                        //判断是否需要回显 ,如果需要使其被选中
                            $option.attr("selected","selected");
                        }
                 $select.append($option);
                 //将内容回显
                 $("#"+position_id).append($select);
                });
                   }, "json");
    }