该函数showRandom每1000毫秒执行一次,但我希望它每random毫秒执行一次..有什么解决办法吗?谢谢!
var random = 1000;
setInterval(function() {random = randomizator(60000,200000);} ,1000);
setInterval(function() {showRandom(random);}, random);
function randomizator(a,b)
{
return Math.floor(Math.random()*b) + a;
}
function showRandom(random)
{
$('#test').text(random);
}
Run Code Online (Sandbox Code Playgroud)
演示:jsFiddle
我需要创建一个数组,其中包含没有 jQuery 的页面中的所有文本。这是我的 html:
<html>
<head>
<title>Hello world!</title>
</head>
<body>
<h1>Hello!</h1>
<p>
<div>What are you doing?</div>
<div>Fine, and you?</div>
</p>
<a href="http://google.com">Thank you!</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我想得到的
text[1] = "Hello world!";
text[2] = "Hello!";
text[3] = "What are you doing?";
text[4] = "Fine, and you?";
text[5] = "Thank you!";
Run Code Online (Sandbox Code Playgroud)
这是我尝试过但在我的浏览器中似乎无法正常工作的内容:
var elements = document.getElementsByTagName('*');
console.log(elements);
Run Code Online (Sandbox Code Playgroud)
附注。我需要使用 document.getElementsByTagName('*'); 并排除“脚本”和“样式”。
基本上我有一个类成分的对象列表,如下所示:
class Ingredient {
public int id;
public String name;
public Ingredient(String name) {
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
所以列表中的每个对象都有一个名称.
现在使用ArrayAdapter我需要一个填充名称的字符串列表.有没有办法将ArrayAdapter与我的成分列表一起使用?这就是它现在的样子
List<Ingredient> ingredientsList= new ArrayList<Ingredient>();
ingredientsList.add(new Ingredient("foo"));
ingredientsList.add(new Ingredient("bar"));
Run Code Online (Sandbox Code Playgroud)