Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.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 未捕获类型错误:无法读取Chrome中的属性_Javascript_Regex - Fatal编程技术网

Javascript 未捕获类型错误:无法读取Chrome中的属性

Javascript 未捕获类型错误:无法读取Chrome中的属性,javascript,regex,Javascript,Regex,我创建了一个脚本,它应该指向每个单独的链接,检查它的售价,如果它的售价等于或低于我输入的价格,它会在标题字符串上显示出来。 无论出于何种原因,在Chrome上执行时,95%的时间会弹出以下错误: 未捕获的TypeError:无法读取null的属性“1” JShint也没有帮助,因为无论我做了什么更改,它都会显示相同的错误。如果有帮助的话,我认为错误在regex行附近 剧本: var IDs = [136758649, 116770724, 136171998, 113325603, 111903

我创建了一个脚本,它应该指向每个单独的链接,检查它的售价,如果它的售价等于或低于我输入的价格,它会在标题字符串上显示出来。 无论出于何种原因,在Chrome上执行时,95%的时间会弹出以下错误: 未捕获的TypeError:无法读取null的属性“1”

JShint也没有帮助,因为无论我做了什么更改,它都会显示相同的错误。如果有帮助的话,我认为错误在regex行附近

剧本:

var IDs = [136758649, 116770724, 136171998, 113325603, 111903483, 116786719, 136172656, 139152118, 121926643, 120759721] //Shortened down to a few IDs
var PriceWanting = Number(prompt("How much is the max you would do?"))
document.write('<p id = "title">Total number bought: 0 items for a total of 0</p>')
var buys = 0
var totalrobuxspent = 0
console.log("Bot started")
var loop = setInterval(function () {
    for (var i = 0; i < IDs.length; i++) {
        $.get(" http://m.roblox.com/items/" + IDs[i] + "/privatesales", function (data) {
            var Regex = /\<span class="currency-robux">([\d,]+)\<\/span\>/
            var PriceSelling = data.match(Regex)[1]
            PriceSelling = Number(PriceSelling.replace(",", ""))
            PriceSelling = PriceSelling * 1
            totalrobuxspent = totalrobuxspent + PriceSelling
            var remaining = PriceWanting - PriceSelling
            if (remaining >= -0.1) {
                buys = buys + 1
                document.getElementById("title").innerHTML = "Total number of items bought: " + buys + " for a total of " + totalrobuxspent
            }
        })
    }
}, 3636) //Long intervals so it doesn't lag too badly; mainly for me testing
var-id=[136758649、1167070724、136171998、113325603、111903483、1167819、136172656、139152118、121926643、120759721]//缩短为几个id
var PriceWanting=Number(提示(“您最多可以做多少?”)
文档。写入(“

购买的总数量:0件,总共0件” var=0 var TotalRobuxWasted=0 日志(“Bot启动”) 变量循环=设置间隔(函数(){ 对于(变量i=0;i=-0.1){ 购买=购买+1 document.getElementById(“title”).innerHTML=“购买的物品总数:“+buys+”表示总共“+TotalRoBuxExponed” } }) } },3636)//间隔很长,因此它的滞后性不会太大;主要是为我测试


您可以检查它是否为空,如下所示:

if (!x) {
    // x is not null; do something here
}

哪里是
s。。。(我知道它们不是必需的,但使用它们是一个好习惯)。在您阅读它之前,请检查它是否返回空值。d您应该给出完整的答案,因为我怀疑您是正确的:)再想一想,我不知道如何检查它是否为空值。有人能告诉我怎么做吗?在LUA中,如果Regex==null,那么。。。但是我知道这是非常不同的。您的
data.match(Regex)[1]
没有找到任何匹配项,因此它返回null并给您一个错误