观察Chrome DevTools中的节点数量,我想知道点击Button1之后dom树的差异以及点击Button2之后的差异.
的index.html
<html>
<head>
<script src="./js/main.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="style/default.css">
</head>
<body>
<div id="buttons">
<div class="button" id="button1">Execute1</div>
<div class="button" id="button2">Execute2</div>
</div>
<div id="main"></div>
<div id="main2"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
main.js
document.addEventListener( "DOMContentLoaded", function() {
var button1 = document.getElementById('button1');
button1.addEventListener('click', function() {
document.getElementById('main').innerHTML += '<div>hello</div>';
});
var button2 = document.getElementById('button2');
button2.addEventListener('click', function() {
var div = document.createElement('div');
div.appendChild(document.createTextNode('hello2'));
document.getElementById('main2').appendChild(div);
});
} );
Run Code Online (Sandbox Code Playgroud)
default.css
#buttons {
display:-webkit-flex;
align-items: center;
}
.button {
height: 30px;
width: 100px;
margin: 5px;
background-color: #0080C0;
color: #FFFFFF; …Run Code Online (Sandbox Code Playgroud) 我编写了一个生成4个随机数字的程序,它应该出现在屏幕上,如下所示:从0000到9999(当然不是按升序排列!).
问题是我遇到过彼此相同的数字.我该如何解决?我只想生成10,000个数字,范围在0000到9999之间,但不是以任何顺序:只是"随机".
这是我到目前为止所写的内容:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#define SIZE 10000
int main(){
srand(time(NULL));
int a[SIZE], b[SIZE], c[SIZE], d[SIZE], i;
FILE *fd = fopen("combinations_rand.txt", "w");
assert(fd);
for(i=0; i<SIZE; i++){
a[i] = rand()%10; //array of first digits
b[i] = rand()%10; //array of second digits, etc...
c[i] = rand()%10;
d[i] = rand()%10;
fprintf(fd, "%d%d%d%d\n", a[i], b[i], c[i], d[i]);
}
fclose(fd);
}
Run Code Online (Sandbox Code Playgroud) 为了我的问题,我创建了一个简单的 HTML 页面,其中的摘录如下:
<table class="fruit-vegetables">
<thead>
<th>Fruit</th>
<th>Vegetables</th>
</thead>
<tbody>
<tr>
<td>
<b>
<a href="https://en.wikipedia.org/wiki/Apple" title="Apples">Apples</a>
</b>
</td>
<td>
<a href="https://en.wikipedia.org/wiki/Carrot" title="Carrots">Carrots</a>
</td>
</tr>
<tr>
<td>
<i>
<a href="https://en.wikipedia.org/wiki/Orange_%28fruit%29" title="Oranges">Oranges</a>
</i>
</td>
<td>
<a href="https://en.wikipedia.org/wiki/Pea" title="Peas">Peas</a>
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我想使用 Jsoup 从名为“Fruit”的第一列中提取数据。因此,结果应该是:
Apples
Oranges
Run Code Online (Sandbox Code Playgroud)
我写了一个程序,摘录如下:
//In reality, it should be connect(html).get().
//Also, suppose that the String `html` has the full source code.
Document doc = Jsoup.parse(html);
Elements table = doc.select("table.fruit-vegetables").select("tbody").select("tr").select("td").select("a");
for(Element element : table){
System.out.println(element.text());
}
Run Code Online (Sandbox Code Playgroud)
这个程序的结果是:
Apples
Carrots …Run Code Online (Sandbox Code Playgroud) html ×2
c ×1
html-parsing ×1
html-table ×1
java ×1
javascript ×1
jsoup ×1
numbers ×1
random ×1