单击/选择选项时,将继续为该选项指定链接

时间:2016-09-22 04:07:11

标签: javascript html

Hello everyone! I just want to ask, when I choose regular in my drop down. The link goes to the regular.html as well as the contractual. How can I do it? Thank you in advance. :)

此处还有我的regular.html代码: regular.html

<html>
<head>
    <title>Drop down</title>
</head>
<body>
    <h1>Regular</h1>
    <select>
        <option href="regular.html">Regular</option>
        <option href="contractual.html">Contractual</option>
    </select>
</body>
</html>

这是合同: contractual.html

<html>
<head>
    <title>Drop down</title>
</head>
<body>
    <h1>Contractual</h1>
    <select>
        <option href="regular.html">Regular</option>
        <option href="contractual.html">Contractual</option>
    </select>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

你可以试试这个:

$('select').change(function(){
    var url = $('option:selected', this).attr('href');
    window.location.href = url;
});

答案 1 :(得分:0)

    <h1>Main Page</h1>
    <select onchange="location = this.options[this.selectedIndex].value;">
        <option value="regular.html">Regular</option>
        <option value="contractual.html">Contractual</option>
    </select>