Multi-select box to assign value to A tag href

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        ul{
            margin: 100px auto;
        }
        ul li{
            list-style:none;
            width: 400px;
            height: 400px;
            border: 1px solid #000;
            margin-right: 4px;
            float: left;
        }
        ul li input{
            margin: 200px 200px;
        }
    </style>
</head>
<body>
<div></div>

    <ul>
        <li>
            <input type="checkbox" name="box" id="name1" checked="true">1
        </li>
        <li>
            <input type="checkbox" name="box" id="name2" value="200">2
        </li>
        <li>
            <input type="checkbox" name="box" id="name3" value="300">3
        </li>
        <li>
            <input type="checkbox" name="box" id="name4" checked="true">4
        </li>
        <a id="gotourl" target="_blank">提交</a>
    </ul>
<script>
    window.onload = function () {
        var gotourl = document.getElementById("gotourl");
        gotourl.onclick =function () {
            GoodsUrl();
        }
    };
    function GoodsUrl() {
        var name2 = document.getElementById('name2');
        var name3 = document.getElementById('name3');
        var gotourl = document.getElementById("gotourl");
        if (name2.checked ===true && name3.checked != true){
            gotourl.href = "http://ecshop/ecshop/goods.php?id=7";
        }else if(name3.checked ===true && name2.checked != true){
            gotourl.href = "http://ecshop/ecshop/goods.php?id=8";
        }else if(name2.checked === true && name3.checked === true){
            gotourl.href = "http://ecshop/ecshop/goods.php?id=9";
        }else{
            gotourl.href = "http://ecshop/ecshop/goods.php?id=6";
        }
    }
</script>
</body>
</html>

Guess you like

Origin blog.csdn.net/weixin_41653910/article/details/84859941