将数组和输入值循环到字段中

时间:2015-04-06 23:49:37

标签: javascript jquery for-loop

我有一个关于自动化价值输入和脚本的脚本的一般性问题。点击。目的是选择站点变量/ concat中的站点到ns1 - ns2,单击id add_gridVanity将值放入输入字段并提交/关闭然后重复该过程直到数组结束。我似乎无法让for循环运行。对不起基本问题。

sites = ["stonegrillla.com","schoolfoodbloomingroll.com","chapmanpizzeria.net","sushimasu.com","hmsbountyla.com","pailinthaicuisine.net","fullhouseseafood.com","cjssgourmetdelicatessen.com","bullsheadexpress.net","breakingbreadsf.net","lscaffe.net","latortagorda.org","pinecrestdiner.net","sunriserestaurant.net","tressf.net","hanazensf.com","piperade.org","mazzatsf.net","gaylordindia.net","thegrovefillmore.com","itstopscoffeeshop.net"]


for (i=0; i<sites.length; i++){

var base = 'ns1,ns2.';
var full = base.concat(sites[i]);
var sub1 = "ns1.".concat(sites[i]);
var sub2 = "ns2.".concat(sites[i]);
var both = sub1+'\n'+sub2;
$("#add_gridVanity").click();
$("#name").val(full);
$("#servers").val(both);
$("#sData").click();
$("#cData").click();
 console.log(sites[i]); //test
};

1 个答案:

答案 0 :(得分:1)

很少有基本的东西,你需要声明变量并添加分号。刚刚在网站后声明了sitesi以及分号。关于javascript的棘手部分甚至是一个带有语法或逗号或分号等的小错误,整个事情都会失败,你也不会意识到这一点,因为它可能非常愚蠢。在浏览器中使用开发工具来检查错误

  var sites = ["stonegrillla.com","schoolfoodbloomingroll.com","chapmanpizzeria.net","sushimasu.com","hmsbountyla.com","pailinthaicuisine.net","fullhouseseafood.com","cjssgourmetdelicatessen.com","bullsheadexpress.net","breakingbreadsf.net","lscaffe.net","latortagorda.org","pinecrestdiner.net","sunriserestaurant.net","tressf.net","hanazensf.com","piperade.org","mazzatsf.net","gaylordindia.net","thegrovefillmore.com","itstopscoffeeshop.net"];


for (var i=0; i<sites.length; i++){

var base = 'ns1,ns2.';
var full = base.concat(sites[i]);
var sub1 = "ns1.".concat(sites[i]);
var sub2 = "ns2.".concat(sites[i]);
var both = sub1+'\n'+sub2;
$("#add_gridVanity").click();
$("#name").val(full);
$("#servers").val(both);
$("#sData").click();
$("#cData").click();
 console.log(sites[i]); //test
}

以上回答仅适用于我似乎无法让for循环运行。一旦你有循环运行,我认为你应该能够弄清楚其余的