如何在弹簧形式中使用jquery填充选择框

时间:2011-06-06 07:06:29

标签: javascript jquery html spring-mvc

我将地图返回到post方法,该方法在alert函数中正确显示。如何将地图的值附加到带有ID课程的选择选项?

<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>

1 个答案:

答案 0 :(得分: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);
});