添加 else if 语句以使用 javascript 在 html 中提取页面

发布于 2024-10-31 05:30:57 字数 2206 浏览 0 评论 0原文

我们有一个由外部公司开发的新网站,但我们遇到了问题。我试图找出一段代码的逻辑,如果满足某些要求,该代码将拉出一个新页面。

首先,这是网站 http://www.winstonind.com/service

对于任何服务商在美国,它会调出谷歌地图和我们的服务商的位置,以获取下拉列表中的任何其他选项,但它不会执行任何操作。我想知道的是,如果选择了中国,它将转到我使用该地区的服务商列表创建的页面,您能帮我吗?我还不太了解 Javascript,而且由于该网站已经上线,所以我无法进行大量修改。

<script type="text/javascript">
                $("#country").change(function(){
                    $(this).val()!='default'?$("#state").hide():$("#state").show();
                });
                var typeChoice;
                $("#step1next").click(function(){
                    typeChoice = $(".mt:checked").val();
                    $(".step.1").removeClass('selected');
                    $(".step.2").addClass('selected');
                    $(".step.1 .sContent").slideUp();
                    $(".step.2 .sContent").slideDown();
                });
                $("#step2next").click(function(){
                    if(typeChoice == 'type1')
                    {
                        $("#mapResult").html('<p style="text-align:center; margin-bottom:5px;">For all service requests that are in-warranty please contact Winston Industries directly.</p><p style="text-align:center;">Toll free: 1-800-234-5286<br/>International: +1-502-495-5400</p>');
                    }else{
                        $("#mapResult").html('');
                        var zip='';
                        $("#state").val()==$("#state").attr('default')?zip='':zip=$("#state").val();

                        //to make distance dynamic, replace 50 with a dynamic value
                        $.post('service/getMap/'+zip+'/50',function(data){
                            $("#mapResult").html(data);
                        });
                    }
                    $(".step.2").removeClass('selected');
                    $(".step.3").addClass('selected');
                    $(".step.2 .sContent").slideUp();
                    $(".step.3 .sContent").slideDown();
                });
                $(".sContent").hide();
                $(".selected .sContent").show();
            </script>   

We have a new website developed by a outside company that we are having issues with. I am trying to figure out the logic on a piece of code that would pull up a new page if some requirements are met.

First of all this is the site http://www.winstonind.com/service

For any servicer in the US it pulls up a Google map and the locations of our servicers for any other options in the drop-down it doesn't do anything. what I would like to know is how I would make is so if china is selected it would go to a page I created with the list of servicers from that region can you help me with this? I don't understand alot of Javascript yet and I cant tinker alot since the site is live.

<script type="text/javascript">
                $("#country").change(function(){
                    $(this).val()!='default'?$("#state").hide():$("#state").show();
                });
                var typeChoice;
                $("#step1next").click(function(){
                    typeChoice = $(".mt:checked").val();
                    $(".step.1").removeClass('selected');
                    $(".step.2").addClass('selected');
                    $(".step.1 .sContent").slideUp();
                    $(".step.2 .sContent").slideDown();
                });
                $("#step2next").click(function(){
                    if(typeChoice == 'type1')
                    {
                        $("#mapResult").html('<p style="text-align:center; margin-bottom:5px;">For all service requests that are in-warranty please contact Winston Industries directly.</p><p style="text-align:center;">Toll free: 1-800-234-5286<br/>International: +1-502-495-5400</p>');
                    }else{
                        $("#mapResult").html('');
                        var zip='';
                        $("#state").val()==$("#state").attr('default')?zip='':zip=$("#state").val();

                        //to make distance dynamic, replace 50 with a dynamic value
                        $.post('service/getMap/'+zip+'/50',function(data){
                            $("#mapResult").html(data);
                        });
                    }
                    $(".step.2").removeClass('selected');
                    $(".step.3").addClass('selected');
                    $(".step.2 .sContent").slideUp();
                    $(".step.3 .sContent").slideDown();
                });
                $(".sContent").hide();
                $(".selected .sContent").show();
            </script>   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就像说晚安 2024-11-07 05:30:57

在关闭之前添加以下内容并修改 url 以指向正确的目录和 url。

if($('#country').val() == 'china'){
    window.location = 'http://www.yourdomain.com/chinaServicesPage';
}


if($('#country').val() == 'canada'){
    window.location = 'http://www.yourdomain.com/swedishServicesPage';
}

</script>

这就是您的选择框代码的样子:

<select name="country" id="country">
                        <option value="default">United States</option>

                        <option value="canada">Canada</option>

                        <option value="china">Greater China</option>

                        <option value="asia_excluding_china">Asia (excluding Greater China)</option>

                        <option value="europe">Europe</option>

                        <option value="latin_america_and_the_caribbean">Latin America and the Caribbean</option>

                        <option value="middle_east">Middle East</option>

                        <option value="africa">Africa</option>

                        <option value="southernpacific">Southern Pacific</option>

                        <option value="united_states">United States</option>

                    </select>

您会注意到第一行中的“id”称为国家/地区。所以我们想要读取用户在国家/地区选择框中放置的值,可以是加拿大、中国、美国等...

Add the following before your closing and modify the url to point to the correct directory and url.

if($('#country').val() == 'china'){
    window.location = 'http://www.yourdomain.com/chinaServicesPage';
}


if($('#country').val() == 'canada'){
    window.location = 'http://www.yourdomain.com/swedishServicesPage';
}

</script>

This is what your select box code looks like:

<select name="country" id="country">
                        <option value="default">United States</option>

                        <option value="canada">Canada</option>

                        <option value="china">Greater China</option>

                        <option value="asia_excluding_china">Asia (excluding Greater China)</option>

                        <option value="europe">Europe</option>

                        <option value="latin_america_and_the_caribbean">Latin America and the Caribbean</option>

                        <option value="middle_east">Middle East</option>

                        <option value="africa">Africa</option>

                        <option value="southernpacific">Southern Pacific</option>

                        <option value="united_states">United States</option>

                    </select>

You will notice that the "id" in the first line is called country. so we want to read the value that the user has placed in the select box of country which could be canada, china, USA, etc...

英雄似剑 2024-11-07 05:30:57

我认为这有点像你想要的:

if(thisThing){ 
   window.location = 'urlA';
}
else { 
   window.location = 'urlB';
}

i think this is somewhat what you wanted:

if(thisThing){ 
   window.location = 'urlA';
}
else { 
   window.location = 'urlB';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文