只选择链路参数

Select with link parameters only

本文关键字:参数 链路 选择      更新时间:2023-09-26

我试图得到一个下拉链接,但我不想使用链接文件名在url只是参数。

代码如下:

<script type="text/javascript">
    function goToNewPage(){
        var url = document.getElementById('list').value;
        if(url != 'none') {
            window.location = url;
        }
    }
</script>
<select name="list" id="list" accesskey="target">
    <option value='none' selected>Choose an item</option>
    <option value="?one">item1</option>
    <option value="?two">item2</option>
<select>
<input type=button value="Go" onclick="goToNewPage()" />

If I use: <option value="index.html?one">item1</option> it will work but:

我如何让它与它一起工作…这样的:

<option value="?one">item1</option> ?

您可以使用document.location.search:

function goToNewPage() {
    var url = document.getElementById('list').value;
    if(url != 'none') {
        document.location.search = url;
    }
}

如果你的链接文件名是"index.html",那么你应该使用:

<script type="text/javascript">
function goToNewPage(){
    var url = document.getElementById('list').value;
    if(url != 'none') {
        window.location = "index.html" + url;
    }
}
</script>