jsp页面中的代码片段
<tr>
<td>性别</td>
<td>
<input type="radio" name="stuSex" value="男" checked="checked" />男
<input type="radio" name="stuSex" value="女" />女
/td>
</tr>
<tr>
<td>性别2</td>
<td>
<select id="gender" name="gender">
<option value="" selected="selected">请选择</option>
<option value="男">男</option>
<option value="女">女</option>
<option value="其他">其他</option>
</select>
</td>
</tr>
<input type="hidden" id="sex" name="sex" value="${student.stuSex}">
js文件中的代码片段
$(document).ready(function() {
var sex = $("#sex").val();
$("select[name='gender']").find("option[value='"+sex+"']").attr("selected",true);
var tempSex=$("#gender").find("option[value='"+sex+"']").text();
var s = document.getElementsByName("stuSex");
for( var i = 0; i < s.length; i++ ){
if(s[i].value == sex ){
$(s[i]).attr("checked",true);
}
}
});