1. 程式人生 > >select 根據後臺傳來的值選中

select 根據後臺傳來的值選中

js中

<script type="text/javascript">
$(document).ready(function(){  
     var key=$("#selectRefundReason").val();
     //根據值讓option選中 
     $("#refundReason option[value='"+key+"']").attr("selected","selected"); 
}); 
</script>

html中

 <span>
                    <input type="hidden" id ="selectRefundReason" value="{$type}"/>
                    <select class="select" size="1" name="type" id="type" onchange="changtype('{:url('carousel/index')}')">
                        <option value="0">商鋪</option>
                        <option value="1">使用者</option>
                     </select>
 </span>


<input type="hidden" id ="selectRefundReason" value="{$type}"/>
隱藏後臺傳來的值,在js中取值