添加elseif语句以使用javascript在html中调出页面
我们有一个由外部公司开发的新网站,我们与之有问题。我试图找出一段代码的逻辑,如果满足某些要求,它将打开一个新页面 首先是这个网站 对于美国的任何服务商,它都会在下拉列表中调出谷歌地图和我们服务商的位置以供选择,但它什么也不做。我想知道的是,如果中国被选中,它会进入我创建的页面,页面上有来自该地区的服务商名单。你能帮我做些什么吗?我还不懂很多Javascript,我也不能修补很多东西,因为这个网站是实时的添加elseif语句以使用javascript在html中调出页面,javascript,jquery,expressionengine,Javascript,Jquery,Expressionengine,我们有一个由外部公司开发的新网站,我们与之有问题。我试图找出一段代码的逻辑,如果满足某些要求,它将打开一个新页面 首先是这个网站 对于美国的任何服务商,它都会在下拉列表中调出谷歌地图和我们服务商的位置以供选择,但它什么也不做。我想知道的是,如果中国被选中,它会进入我创建的页面,页面上有来自该地区的服务商名单。你能帮我做些什么吗?我还不懂很多Javascript,我也不能修补很多东西,因为这个网站是实时的 <script type="text/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>
$(“#国家”)。更改(功能(){
$(this.val()!='default'?$(“#state”).hide():$(“#state”).show();
});
变量类型选择;
$(“#step1next”)。单击(函数(){
typeChoice=$(“.mt:checked”).val();
$(“.step.1”).removeClass('selected');
$(“.step.2”).addClass('selected');
$(“.step.1.sContent”).slideUp();
$(“.step.2.sContent”).slideDown();
});
$(“#step2next”)。单击(函数(){
if(typeChoice==“type1”)
{
$(“#mapreult”).html(“对于保修期内的所有服务请求,请直接联系Winston Industries。
免费电话:1-800-234-5286
国际:+1-502-495-5400
”;
}否则{
$(“#mapreult”).html(“”);
var-zip='';
$(“#状态”).val()=$(“#状态”).attr('default')?zip='':zip=$(“#状态”).val();
//要使距离动态,请将50替换为动态值
$.post('service/getMap/'+zip+'/50',函数(数据){
$(“#mapreult”).html(数据);
});
}
$(“.step.2”).removeClass('selected');
$(“.step.3”).addClass('selected');
$(“.step.2.sContent”).slideUp();
$(“.step.3.sContent”).slideDown();
});
$(“.scocontent”).hide();
$(“.selected.scocontent”).show();
我想这正是您想要的:
if(thisThing){
window.location = 'urlA';
}
else {
window.location = 'urlB';
}
在关闭前添加以下内容,并修改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>
if($('#country').val()=='china'){
window.location=http://www.yourdomain.com/chinaServicesPage';
}
如果($('#country').val()='canada'){
window.location=http://www.yourdomain.com/swedishServicesPage';
}
这是您的选择框代码的外观:
<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”称为country。因此,我们想读取用户在国家选择框中输入的值,这些国家可能是加拿大、中国、美国等。谢谢,我甚至没有想到他们使用jQuery来实现这一点。您怎么知道?$通常用于jQuery。其他框架和代码也可以定义$,但从使用的方法来看,
addClass
,removeClass
和其他方法都是针对jQuery的。谢谢Justin 808你能为jQuery初学者推荐一本好书吗?如果你通晓javascript,使用jQuery网站——这是我推荐的最好的方法。类型3从何而来?你能给我解释一下吗?我是新来的。我已经把代码修改成了你的实际文档元素。。。因此,它正在检查div命名的country的值是否为“china”,然后它将转到某个页面。