在javascript中更改if条件
请把灯给我。我正在使用一些javascript来实现一个表单的行为。正如我在下面提供的代码中所看到的,如果表单提交成功,将显示一条消息。我需要的不是这个消息,而是一个要打开的URL。我猜必须在if中进行更改(resp.result==“success”)。还要注意,else条件必须相同在javascript中更改if条件,javascript,Javascript,请把灯给我。我正在使用一些javascript来实现一个表单的行为。正如我在下面提供的代码中所看到的,如果表单提交成功,将显示一条消息。我需要的不是这个消息,而是一个要打开的URL。我猜必须在if中进行更改(resp.result==“success”)。还要注意,else条件必须相同 function mce_success_cb(resp){ $('#mce-success-response').hide(); $('#mce-error-response').hide();
function mce_success_cb(resp){
$('#mce-success-response').hide();
$('#mce-error-response').hide();
if (resp.result=="success"){
$('#mce-'+resp.result+'-response').show();
$('#mce-'+resp.result+'-response').html(resp.msg);
$('#mc-embedded-subscribe-form').each(function(){
this.reset();
});
} else {
var index = -1;
var msg;
try {
var parts = resp.msg.split(' - ',2);
if (parts[1]==undefined){
msg = resp.msg;
} else {
i = parseInt(parts[0]);
if (i.toString() == parts[0]){
index = parts[0];
msg = parts[1];
} else {
index = -1;
msg = resp.msg;
}
}
} catch(e){
index = -1;
msg = resp.msg;
}
try{
if (index== -1){
$('#mce-'+resp.result+'-response').show();
$('#mce-'+resp.result+'-response').html(msg);
} else {
err_id = 'mce_tmp_error_msg';
html = '<div id="'+err_id+'" style="'+err_style+'"> '+msg+'</div>';
var input_id = '#mc_embed_signup';
var f = $(input_id);
if (ftypes[index]=='address'){
input_id = '#mce-'+fnames[index]+'-addr1';
f = $(input_id).parent().parent().get(0);
} else if (ftypes[index]=='date'){
input_id = '#mce-'+fnames[index]+'-month';
f = $(input_id).parent().parent().get(0);
} else {
input_id = '#mce-'+fnames[index];
f = $().parent(input_id).get(0);
}
if (f){
$(f).append(html);
$(input_id).focus();
} else {
$('#mce-'+resp.result+'-response').show();
$('#mce-'+resp.result+'-response').html(msg);
}
}
} catch(e){
$('#mce-'+resp.result+'-response').show();
$('#mce-'+resp.result+'-response').html(msg);
}
}
}
功能mce\u成功\u cb(resp){
$(“#mce成功响应”).hide();
$(“#mce错误响应”).hide();
如果(响应结果=“成功”){
$(“#mce-”+resp.result+'-response').show();
$('#mce-'+resp.result+'-response').html(resp.msg);
$(“#mc嵌入式订阅表单”)。每个(函数(){
这是reset();
});
}否则{
var指数=-1;
var-msg;
试一试{
变量部分=相应的消息拆分('-',2);
if(部件[1]==未定义){
msg=resp.msg;
}否则{
i=parseInt(部分[0]);
如果(i.toString()==部件[0]){
索引=零件[0];
msg=零件[1];
}否则{
指数=-1;
msg=resp.msg;
}
}
}捕获(e){
指数=-1;
msg=resp.msg;
}
试一试{
如果(索引==-1){
$(“#mce-”+resp.result+'-response').show();
$('#mce-'+resp.result+'-response').html(msg);
}否则{
err_id='mce_tmp_error_msg';
html=''+msg+'';
var输入_id='#mc_嵌入_注册';
变量f=$(输入_id);
如果(F类型[索引]=“地址”){
输入_id='#mce-'+fnames[index]+'-addr1';
f=$(输入id).parent().parent().get(0);
}else if(f类型[索引]='date'){
输入_id='#mce-'+fnames[index]+'-month';
f=$(输入id).parent().parent().get(0);
}否则{
输入#id='#mce-'+fnames[index];
f=$().parent(输入_id).get(0);
}
如果(f){
$(f).附加(html);
$(输入_id).focus();
}否则{
$(“#mce-”+resp.result+'-response').show();
$('#mce-'+resp.result+'-response').html(msg);
}
}
}捕获(e){
$(“#mce-”+resp.result+'-response').show();
$('#mce-'+resp.result+'-response').html(msg);
}
}
}
这个怎么样
window.location = "http://www.example.com";
这个怎么样
window.location = "http://www.example.com";
我需要的不是这个消息,而是一个要打开的URL
好的,用以下代码替换不需要的代码部分:
window.location = "yourURLhere";
如果您打算在新窗口中打开页面,请尝试以下操作:
window.open("yourURLhere", "AWindowName", strWindowFeatures);
其中,strWindowFeatures
是一个可选参数,用于设置新窗口的大小、位置等。请参阅MDN以获取完整信息
我需要的不是这个消息,而是一个要打开的URL
好的,用以下代码替换不需要的代码部分:
window.location = "yourURLhere";
如果您打算在新窗口中打开页面,请尝试以下操作:
window.open("yourURLhere", "AWindowName", strWindowFeatures);
其中,
strWindowFeatures
是一个可选参数,用于设置新窗口的大小、位置等。请参见MDN以获取完整信息。除非我误解了您的问题,否则您只需要一个:
window.location = 'http://www.domain.com';
除非我误解了你的问题,否则你只需要一个:
window.location = 'http://www.domain.com';
if(resp.result==“success”){
block中的行。确保有效!window.location命令仅在新窗口中打开?是否有父级选项?确保有效!window.location命令仅在新窗口中打开?是否有父级选项?