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呢? 感覺和回調函數的變量作用域有關系。望不吝賜教,多謝!
javascript 變量問題請教
弒天下
2018-10-19 16:09:52