1

我正在尝试向我的网站添加滚动功能。该标签适用于此,如果选择了一个选项,我想加载一个新网站。这是我目前拥有的。

<body>
<script type="text/javascript">
    $('document').ready(function(){
                        $('#button').click(function(){
                                var val = document.getElementById("scroll");
                                                       if(val.options[val.selectedIndex].value == 1){
                                                       window.location.replace("/passbook.html");
                                                       }else if(val.options[val.selectedIndex].value == 2){
                                                       window.location.replace("/settings.html");
                                                       }
                                                       });
                                           });
                        });
    </script>

<select id="scroll" style="height:50px; width:150px;" >
<optgroup label="Home">
<option value="0" >Home</option>
</optgroup>
<optgroup label="Page" >
<option value="1" >Page</option>
</optgroup>
<optgroup label="Other" >
<option value="2" >Settings</option>
</optgroup>
</select>
<button type="button">Go</button>
</body>

现在点击 go 时没有明显的变化。我想重定向到这些页面。我知道 window.location.replace(Your URL Here) 有效。有人可以帮我处理 javascript 吗?

4

2 回答 2

1

出色地!据我了解你的问题。如果您想在单击选项时重定向您的客户,那么这可能会有所帮助

   <select id="opts" onchange="GotoPage()">
        <option value="0">SELECT</option>
        <option value="index.html">Home</option>
        <option value="page.html">Page</option>
        <option value="setting.html">Setting</option>
        <option value="go.html">Go</option>
    </select>

在脚本中:

<script type="text/javascript">
function GotoPage()
{
   var loc = document.getElementById('opts').value;
   if(loc!="0")
   window.location = loc;
}
</script>
于 2013-11-14T19:36:51.920 回答
0

添加name="scroll"到选择标签

取期权的价值var val = $('select[name="scroll"] option:selected').text();

<body>
    <select id="scroll" name="scroll" style="height:50px; width:150px;" >
    <optgroup label="Home">
    <option value="0" >Home</option>
    </optgroup>
    <optgroup label="Page" >
    <option value="1" >Page</option>
    </optgroup>
    <optgroup label="Other" >
    <option value="2" >Settings</option>
    </optgroup>
    </select>
    <button type="button">Go</button>
    </body>

js

<script type="text/javascript">
    $('document').ready(function(){
                        $('#button').click(function(){
                                var val = $('select[name="scroll"] option:selected').text();
                                                       if(val == 1){
                                                       window.location.replace("/passbook.html");
                                                       }else if(val == 2){
                                                       window.location.replace("/settings.html");
                                                       }
                                                       });
                                           });
                        });
    </script>
于 2013-11-14T19:41:24.423 回答