所以我得到了一个看起来像这样的html
<a href="1" class="link">
<div class="div1">
<div class="A"></div>
</div>
</a>
<a href="2" class="link">
<div class="div1">
<div></div>
</div>
</a>
<a href="3" class="link">
<div class="div1">
<div class="C"></div>
</div>
</a>
我想获取第二个div标签并将其放入数组,使其变为这样
arr = [A,0,C]
答案 0 :(得分:0)
通过选择器定位div标签(具有“ div1”类)并查找内部div 并检查它是否具有此类。
package main
import (
"encoding/json"
"fmt"
)
type ResultStruct struct {
Result *[]map[string]string `json:"result"`
}
func main() {
//case 1
var jsonData1 ResultStruct
err := json.Unmarshal([]byte(`{"result":[{"Name":"ADF","Job":"ENG"},{"Name":"ASK","Job":"TEST"}]}`), &jsonData1)
fmt.Println(err)
fmt.Println(jsonData1.Result)
fmt.Println()
//case 2
var jsonData2 ResultStruct
err = json.Unmarshal([]byte(`{}`), &jsonData1)
fmt.Println(err)
fmt.Println(jsonData2.Result)
}
答案 1 :(得分:0)
@Configuration
@EnableWebSecurity
class SecurityConfiguration : WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
http.authorizeRequests()
.antMatchers("/health").permitAll()
.anyRequest().authenticated()
.and()
.oauth2Login()
.permitAll()
}
}
var arr = $('.div1 > div').map(function(){
return $(this).attr('class') == undefined? 0 : $(this).attr('class');
}).get();
console.log(arr);
答案 2 :(得分:0)
setdefault
答案 3 :(得分:0)
Oneliner
let arr = [...document.querySelectorAll(".link>.div1>div")].map(div => div.className || "0")
console.log(arr)
<a href="1" class="link">
<div class="div1">
<div class="A"></div>
</div>
</a>
<a href="2" class="link">
<div class="div1">
<div></div>
</div>
</a>
<a href="3" class="link">
<div class="div1">
<div class="C"></div>
</div>
</a>