由于您使用jQuery标记了您的问题,我假设您在页面的某个位置使用它,因此您将 HTML 更改为:
<select name="testselect" id="testselect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
并将其添加到您的$(document).ready( .. );
调用中以捕获对该下拉列表的更改,如下所示:
$(document).ready(function() {
$('#testselect').change(function() {
// POST the changed value to a method in a controller that can accept
// a parameter and that'll set the session variable for you
$.post("http://location/to/controller/method/",
{ testselect: this.value },
'html'
);
});
});