jsp頁面,給下拉列表自動選中指定的選項

有很多時候我們需要選中下拉列表中的選項爲我們數據庫中保存的選項,那麼如何做呢?

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章