简体   繁体   English

下拉列表项

[英]Drop down list item

I have a <select> field, which shows a hidden div on selecting a list item. 我有一个<select>字段,其中显示了选择列表项时的隐藏div。

There are tree items in the <select> and each item shows the hidden div. <select>有树项目,每个项目都显示隐藏的div。

What I need is when I have selected the 3rd item and I refresh the page, the 3rd item should no longer be selected, but it should change to the 1st item. 我需要的是选择第三个项目并刷新页面后,不再选择第三个项目,而是将其更改为第一个项目。

I have tried selected="selected" in the <option> code but it did not work. 我在<option>代码中尝试了selected="selected" ,但没有成功。

 <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script>

<script type='text/javascript'>
//<![CDATA[ 
$(window).load(function(){
$("#column_select").change(function() {         
    $('div[id^=layout_select]').hide();
    $('.'+this.value).show();  
});

});
//]]>  

</script>
</head>

<body>
  <!-- this controls the selection of columns --> 
<select name="column_selec" id="column_select">     
    <option value="col1" selected="selected">1 column</option>     
    <option value="col2">2 column</option>     
    <option value="col3">3 column</option> 
</select>   


<!-- this controls the selection of columns -->  

<!-- if '1 column' is selected this div is shown --> 
<div id="layout_select1" class="col1">You only have one column!</div>  

<!-- if '2 column' is selected this div is shown --> 
<div id="layout_select2" class="col2" style="display:none">    
    <input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay1" '.$layout1.' />imaage1
    <input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay2" '.$layout2.' />imaage2    </div>  
<!-- if '3 column' is selected this div is shown -->
<div id="layout_select3" class="col3" style="display:none">
    <input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay3" '.$layout3.' />imaage3
    <input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay4" '.$layout4.' />imaage4    
    <input type="radio" id="'.$option[0].'" name="'.$option[0].'" size="25" value="lay5" '.$layout5.' />imaage5
</div>

try this code , this will select the first option in the drop down when page will refresh 尝试此代码,这将在页面刷新时选择下拉菜单中的第一个选项

 $(document).ready(function(){
     $('#column_select').val('col1');
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM