2014-07-25 54 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); 
});