有很多時候我們需要選中下拉列表中的選項爲我們數據庫中保存的選項,那麼如何做呢?
<input type="hidden" id="hidTypeId" value="<ww:property value='news.newsType'/>" /><!-- 隱藏域 -->
<script type="text/javascript">
$(function(){ //類型的下拉列表
if($('#hidTypeId').val() != null && ""!=$('#hidTypeId')){
var num111 = $('#hidTypeId').val();
$("#txtnewsType option[value='"+num111+"']").attr("selected", "selected");
}else{
// alert(0);
}
});
</script>