控制台错误:意外的标识符?

时间:2014-07-25 20:00:42

标签: jquery

在下面的代码中,它应该根据您在输入框中输入的内容生成具有特定属性的iframe,然后每隔.1秒“扫描”一次,如果在每次扫描中满足某些要求,则单击按钮。代码一直给我错误SyntaxError: Unexpected identifier,我不知道如何解决它;我找不到任何拼写错误或任何东西

感谢;这是我的代码

$(function() {
$("html").html("");
$("<input placeholder='ID...'><input placeholder='Price...' ><input type='button' value='Add'>").prependTo("body");
$("input[type='button']").click(function() {    
    var scanId = parseInt($("input").first().val());
    var scanPrice = parseInt($("input").first().next().val());
    $("<br /><p>Scanning Item "+scanId+" for "+scanPrice+" coins</p><br /><iframe src='http://meepcity.com/item.php?id="+scanId+"' height='250px' width='500px' price='"+scanPrice+"' scan='"+scanId+"'></iframe>").appendTo("body");
    $("input").first().val("");
    $("input").first().next().val("");
    var current = $("iframe").last();
    $(current).load(function() { 
        var currentId = parseInt($(this).attr("scan"));
        var currentPrice = parseInt($(this).attr("price"));
        var x = $(this).contents().find(".item-information-buySellerAsset:first"); 
        var y = $(this).contents().find(".purchase-asset:first");
        var z = parseInt($(this).contents().find("#price:first").text());
        if (scanningPrice >= z && x.length>0 and y.length>0) { 
            x[0].click();
            console.log("Attempted to buy");
            y[0].click();
        }
    });
});
setInterval(function() {
    $("iframe").each(function() {
        $(this).load(function() { 
            var scanningId = parseInt($(this).attr("scan"));
            var scanningPrice = parseInt($(this).attr("price"));
            var x2 = $(this).contents().find(".item-information-buySellerAsset:first"); 
            var y2 = $(this).contents().find(".purchase-asset:first");
            var z2 = parseInt($(this).contents().find("#price:first").text());
            if (scanningPrice >= z2 && x2.length>0 and y2.length>0) { 
                x2[0].click();
                console.log("Attempted to buy");
                y2[0].click();
            }
            var src = $(this).attr("src");
            $(this).attr("src", src);
        });
    });
}, 100);
});

1 个答案:

答案 0 :(得分:0)

if语句中有文字and。将它们替换为&&,它应该可以解决您的问题:

$(function() {
    $("html").html("");
    $("<input placeholder='ID...'><input placeholder='Price...' ><input type='button' value='Add'>").prependTo("body");
    $("input[type='button']").click(function() {    
        var scanId = parseInt($("input").first().val());
        var scanPrice = parseInt($("input").first().next().val());
        $("<br /><p>Scanning Item "+scanId+" for "+scanPrice+" coins</p><br /><iframe src='http://meepcity.com/item.php?id="+scanId+"' height='250px' width='500px' price='"+scanPrice+"' scan='"+scanId+"'></iframe>").appendTo("body");
        $("input").first().val("");
        $("input").first().next().val("");
        var current = $("iframe").last();
        $(current).load(function() { 
            var currentId = parseInt($(this).attr("scan"));
            var currentPrice = parseInt($(this).attr("price"));
            var x = $(this).contents().find(".item-information-buySellerAsset:first"); 
            var y = $(this).contents().find(".purchase-asset:first");
            var z = parseInt($(this).contents().find("#price:first").text());
            if (scanningPrice >= z && x.length>0 && y.length>0) { // replaced "and"
                x[0].click();
                console.log("Attempted to buy");
                y[0].click();
            }
        });
    });
    setInterval(function() {
        $("iframe").each(function() {
            $(this).load(function() { 
                var scanningId = parseInt($(this).attr("scan"));
                var scanningPrice = parseInt($(this).attr("price"));
                var x2 = $(this).contents().find(".item-information-buySellerAsset:first"); 
                var y2 = $(this).contents().find(".purchase-asset:first");
                var z2 = parseInt($(this).contents().find("#price:first").text());
                if (scanningPrice >= z2 && x2.length>0 && y2.length>0) { // replaced "and"
                    x2[0].click();
                    console.log("Attempted to buy");
                    y2[0].click();
                }
                var src = $(this).attr("src");
                $(this).attr("src", src);
            });
        });
    }, 100);
});
相关问题