function 里如何使用 if 语句

function robinTest(type){
swal({
title: "通道测试",
text: "请输入要测试支付的金额"
+"回调url",showCancelButton: true,
html: true,
confirmButtonText: "确认测试" ,
type: "prompt",
}, function(){

           window.open('<?php echo url::s("index/service/robinTest");?>' + '?amount=' + $('#amount').val() +     '&callback_url=' + $('#callback_url').val() + "&type=" + type);
---->          这里amount 是 我要提交的金额,我想加一个if语句在这里
---->          如果amount 金额是300,  "&type=" + type  就变成"&type=" + 10 ,这样固定他的type类型
---->          如果amonut 金额是其他数字  "&type=" + type  就变成"&type=" + 15
---->          不知道if语句加哪里,自己尝试了结果导致这个提交框都打不开

---->          下面代码可以不用管
           location.href='';
          })

     $('.showSweetAlert fieldset input').attr('type','hidden');
     $('#amount').val('1.00');
     $('#callback_url').val('<?php echo URL_ROOT; ?>/index/index/callback.do');

  }
讨论数量: 1

var amount = $('#amount').val();
// ----> 如果amount 金额是300, "&type=" + type 就变成"&type=" + 10 ,这样固定他的type类型
// ----> 如果amonut 金额是其他数字 "&type=" + type 就变成"&type=" + 15
var type = amount == 300 ? 10 : 15;
window.open('<?php echo url:: s("index/service/robinTest");?>?amount=' + amount + '&callback_url=' + $('#callback_url').val() + '&type=' + type);

// ----> 下面代码可以不用管
// location.href='';
// })

 $('.showSweetAlert fieldset input').attr('type','hidden');
 $('#amount').val('1.00');
 $('#callback_url').val('<?php echo URL_ROOT; ?>/index/index/callback.do');
4年前 评论
AegisforPhP (楼主) 4年前
GeniusDiapers (作者) 4年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!