2014-07-25 75 views
0

在下面的代碼中,應該根據您在輸入框中輸入的內容製作具有某些屬性的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); 
}); 
+0

控制檯是否不會給您顯示錯誤所在行的堆棧跟蹤? –

+0

否;我不會在一個文件中運行它我只是粘貼它,所以它不會 – user3786876

+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); 
});