Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 价格销售没有定义。但是,确实如此_Javascript_Jquery - Fatal编程技术网

Javascript 价格销售没有定义。但是,确实如此

Javascript 价格销售没有定义。但是,确实如此,javascript,jquery,Javascript,Jquery,我发现错误PriceSelling未定义。但事实上,我知道它在页面上,因为它将它记录在控制台中。请帮忙!谢谢 $.get(window.location, function(data){ var regex=/<span class="it " data-se="item-privatesale-price">([\d,]+)<\/span>/; var PriceSelling = data.match(regex)[1]; console.lo

我发现错误
PriceSelling
未定义。但事实上,我知道它在页面上,因为它将它记录在控制台中。请帮忙!谢谢

$.get(window.location, function(data){
   var regex=/<span class="it " data-se="item-privatesale-price">([\d,]+)<\/span>/;
   var PriceSelling = data.match(regex)[1];  
    console.log(PriceSelling);
});

function get(name){
   if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
      return decodeURIComponent(name[1]);
} 

if (get('bot') && get('expecting') && get('expecting') == PriceSelling) {
console.log("It's a go!");
document.getElementsByClassName('conf-buy-now btn-primary btn-medium PurchaseButton ')[0].click();
//document.getElementById('conf-confirm-btn').click();
}; 
$.get(窗口、位置、函数(数据){
var regex=/([\d,]+)/;
var PriceSelling=data.match(regex)[1];
控制台日志(价格销售);
});
函数get(名称){
if(name=(新的RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)).exec(location.search))
返回组件(名称[1]);
} 
if(get('bot')&&get('expecting')&&get('expecting')==价格销售){
log(“开始了!”);
document.getElementsByClassName('conf-buy-now btn primary btn medium PurchaseButton')[0]。单击();
//document.getElementById('conf-confirm-btn')。单击();
}; 

它在传递给
$的回调函数的作用域中定义。get

但它没有在全球范围内定义

你可以

var PriceSelling;

$.get(window.location, function(data){
  var regex=/<span class="it " data-se="item-privatesale-price">([\d,]+)<\/span>/;
  PriceSelling = data.match(regex)[1];  
  console.log(PriceSelling);
});

function get(name){
  if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
    return decodeURIComponent(name[1]);
} 

if (get('bot') && get('expecting') && get('expecting') == PriceSelling) {
  console.log("It's a go!");
  document.getElementsByClassName('conf-buy-now btn-primary btn-medium PurchaseButton ')[0].click();
  //document.getElementById('conf-confirm-btn').click();
} 

PriceSelling未在您调用它的范围内定义。为什么它会记录它?它会记录,因为PriceSelling声明和您的console.log在同一范围内。
$.get(window.location, function(data){
  var regex=/<span class="it " data-se="item-privatesale-price">([\d,]+)<\/span>/;
  var PriceSelling = data.match(regex)[1];  
  console.log(PriceSelling);

  function get(name){
    if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
      return decodeURIComponent(name[1]);
  } 

  if (get('bot') && get('expecting') && get('expecting') == PriceSelling) {
    console.log("It's a go!");
    document.getElementsByClassName('conf-buy-now btn-primary btn-medium PurchaseButton ')[0].click();
    //document.getElementById('conf-confirm-btn').click();
  } 
});