<form method="post">
roomName : <input type="text" name="roomName" value="<%=room.roomName%>"/><br/>
roomContent:<textarea name="roomContent"><%=room.roomContent%></textarea><br/>
roomCreateUser:<input type="text" value="<%=room.roomCreateUser%>" name="roomCreateUser"/><br/>
roomChat:<input type="radio" name="roomChat" value="public" checked>公聊<input type="radio" name="roomChat" value="secret" >私聊<br/>
<input type="hidden" name="id" value="<%=room._id%>"/>
<input type="submit" value="submit"/>
<input type="reset" value="reset"/>
</form>
<script>
function chatradio(cName,cValue){
var cObj = document.getElementsByName(cName);
for(var i = 0;i < cObj.length;i++){
if(cObj[i].value == cValue){
cObj[i].checked = 'checked';
}
}
};
chatradio('roomchat','<%=room.roomChat%>');
</script>
我想將後台已經有的roomChat值給html頁面上對應的值checked一下,再顯示到html頁面的對應選項上,在網上找到了上述的方法自己改了一下變成了上面的代碼,但是哪裡還出了問題,導致仍然不能正確checked後台的值?