js操作dom节点
eg:
<div class="right"> <label for="1"> <input type="radio" name="radio" value="1">1 </label> <label for="2"> <input type="radio" name="radio" value="2">2 </label> <label for="3"> <input type="radio" name="radio" value="3">3 </label> <label for="4"> <input type="radio" name="radio" value="4">4 </label> </div>
// 通过类名获取dom let rightNodes = document.getElementsByClassName(‘right‘) // 获取元素的所有子节点 let rightChildNodes = document.getElementsByClassName(‘right‘)[0].childNodes // 获取元素的第一层子节点 let labelNodes = document.getElementsByClassName(‘right‘)[0].children // 通过name属性获取节点 let nameNodes = document.getElementsByName("radio")
jquery操作dom节点
$(function(){ console.info(‘1‘, $(‘.right input‘)) })