繁体   English   中英

单击时如何自动更改选项标签的所选项目

[英]How to automatic change the selected item of an option tag when on click

我想使用选项标签动态更改所选项目。 下拉按钮中的以下值是另一个页面的链接。 但是结果是,当我在下拉按钮中选择一个值时,option标签的值没有改变。

这是我的代码:

<select name="select_item" class="select_item" id="menu1" onchange="function();">
                            <option value="<?= base_url('index/products'); ?>">Default sorting</option>
                            <option value="<?= base_url('index/prod_sort1'); ?>">Sort by A to Z</option>

                        </select>
                        <script type="text/javascript">
                            var urlmenu = document.getElementById( 'menu1' );
                            urlmenu.onchange = function() {
                            window.open( this.options[ this.selectedIndex ].value,"_self" );
                            };
                            </script>

试试这个代码

  <script type="text/javascript"> var urlmenu = document.getElementById( 'menu1' ); urlmenu.onchange = function() { window.location.href = urlmenu.options[urlmenu.selectedIndex].value; } </script> 

暂无
暂无

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

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