2011-06-06 99 views
0

我将映射返回到post方法,该方法在alert函数中正确显示。如何将地图的值附加到id选择课程的选项中?如何在弹簧窗体中使用jquery填充选择框

<script type="text/javascript" > 
$(document).ready(function(){ 
     $("select#dept").change(function(){ 
      alert("inside jquery1"); 
     $.post("getCourses.htm",{depName: $(this).val()}, function(j){ 
      $.each(j, function(key, value) { 
        alert(key + ': ' + value); 
        }); 
     }); 
     }); 
    }); 
</script> 
</head> 
<body> 
<h6>Set Course Fee</h6> 
<form:form method="POST" commandName="courseFee"> 
<table cellspacing="7"> 
    <tr> 
     <td>Department:</td> 
     <td><form:select path="pk.dept" id="dept"> 
      <form:option value="select" label="select"/> 
      <form:options items="${deptList}"/> 
     </form:select></td> 
    </tr> 

    <tr> 
     <td>Course:</td> 
     <td><form:select path="pk.course" id="course"> 
     </form:select></td> 
    </tr> 
    <tr> 
     <td><input type="submit" value="Save" ></td> 
    </tr> 
</table> 
</form:form> 
+0

如何变量'j'格式化? – 2011-06-06 07:14:15

回答

1

我想试试这个:

$.post("getCourses.htm",{depName: $(this).val()}, function(j){ 
    var opts = ''; 
    $.each(j, function(key, value) { 
    opts += '<option value="'+value+'">'+key+'</option>'; 
    }); 
    $('#course').html(opts); 
});