基于案例陈述的重定向

时间:2018-01-31 03:53:49

标签: javascript

我使用以下代码创建一个菜单,当单击一个菜单时,它会将您带到case语句中的指定URL。我不明白在每个案例陈述中使用什么才能使其发挥作用。这是代码,现在它点击时无处可去:

<body>
        <div id="page3" class="page">
            <div class="form">
                    <div class="text">4 Item Menu</div>
                    <div class="selection" id="fs_3"></div>
                </div>
            </div>
        </div>

        <script src="plugin/react-with-addons.min.js" charset="utf-8"></script>
        <script src="plugin/react-dom.min.js" charset="utf-8"></script>
        <script src="plugin/app.js" charset="utf-8"></script>

        <script type="text/javascript">
        new CA_select({
            selector: document.getElementById('fs_3'),
            iconColor: '#fff',
            bgColor: '#00BCD4',
            items: [
                {class: "fa-thumbs-up"},
                {class: "fa-thumbs-down"},
                {class: "fa-arrow-right"},
                {class: "fa-arrow-left"},
            ],
            callback: true,
            change: (ret) => {
                 switch(ret) {
        case "0":
         window.location.assign("http://www.google.com");
         break;
        case "1":
         window.location.assign("http://www.cnn.com");
         break;
        case "2":
         window.location.assign("http://www.msn.com");
         break;
        case "3":
         window.location.assign("http://www.espn.com");
         break;              
   }                
        }
        })
        </script>
    </body>

1 个答案:

答案 0 :(得分:0)

你必须在html中添加form标签,然后你可以使用javascript中的动作 在case中添加

 document.getElementById("myForm").action="http://www.google.com";
 document.getElementById("myForm").submit();

和html

<form id="myForm" action="">
<div id="page3" class="page">
            <div class="form">
                    <div class="text">4 Item Menu</div>
                    <div class="selection" id="fs_3"></div>
                </div>
            </div>
        </div>
</form>

检查How to set form action through JavaScript?