js中的代码如下:
$('#submit').click(function postPayInfo() { orderID = $('#payQrcode').attr('value'); console.log(orderID); //位置A console.log(createLink('weipay', 'finishpay',orderID)); //位置B paystatus = $.ajax({url:createLink('weipay', 'finishpay',orderID),async:false}); alert(paystatus); });
console.log 结果:
其中第二行是createLink的返回值。
请问一下,为什么位置A可以打印出orderID, 然而位置B的orderID却是undefine. 我记得js中函数内部是可以访问函数外部的变量的呢。 这里 位置B内部要怎么样才能访问到orderID呢? 感觉和回调函数的变量作用域有关系。
望不吝赐教,多谢!
MMTTMM
相关分类