没有定义PriceSelling.但是,它是
PriceSelling is not defined. But, it is
我得到错误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 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();
}
但是当你不会得到ReferenceError
时,它不会很好,因为PriceSelling
总是undefined
。
但是我注意到你正试图马上使用回应。您必须在回调中使用它,该回调将在收到响应后调用。
您可能会受益于如何从异步调用返回响应?
$.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();
}
});
相关文章:
- 控制台返回var不是't定义,但它是
- 为什么不是'我的函数在解析云代码中工作吗?当我在Angular和Express中测试时,它是有效的
- 当读取文件时,浏览器打开良好,但它是空白浏览器
- 文本字段显示它是有效的,即使它在ExtJS中是无效的
- Javascript:获取“;FORM”;它是在.html到外部.js文件中创建的
- 代理一个网站能够在iframe中进行所见即所得编辑-它是如何工作的
- javascript字符串替换$1(如果它是某个值)
- CORS——它是客户端的东西,服务器端的东西,还是传输级别的东西
- 获取boolen h2.它是空的还是没空?在Jquery中
- Javascript中的国际象棋棋盘制造商.代码有效.但是它是如何工作的
- 如果从文件输入按钮调用 .ajaxSubmit() 时,它是必需的表单
- JavaScript - 多参数函数,它是多个图像库的字符串
- OpenVPN与节点,它是如何工作的
- Javascript/jQuery - “无法调用未定义的方法'push'”,而它是定义的
- 禁用另一个元素内的元素,除非它是按钮
- 理解Javascript中的“未定义”:它是如何工作的,如何安全地检查它以及是否可以重新分配
- 尝试使用jQuery检索URL的一部分;它是有效的,但是字符串是无效的;t返回
- 程序可以工作,但是Code Academy不承认它是正确的
- 没有定义PriceSelling.但是,它是
- 我不明白排序方法在这种情况下是如何工作的,我认为它是按字母顺序工作的,但是 #39;光线里的字不是,为什么