jQuery DOM操作对象
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="jquery-3.4.1.min.js"></script> <title>Document</title> </head> <body> <ul> <li id="bj" name="beijing" xxx="yyy">北京</li> <li id="tj" name="tianjin" >天津</li> </ul> <input type="checkbox" id="hobby" checked="checked"> </body> <script> //获取北京节点的name的属性值 alert($("#bj").attr("name")); //设置北京节点的name属性值为dabeijing $("#bj").attr("name","dabeijing"); alert($("#bj").attr("name")); $("#bj").attr("discription","didu"); alert($("#bj").attr("discription")); //删除北京节点的name属性并检验name属性的存在 $("#bj").removeAttr("name"); alert($("#bj").attr("name")); //获取hobby的选中状态 alert($("#hobby").attr("checked")); /** * jQuery新增函数 * prop property * prop函数适用于固有属性: * checked = checked selected=selected * attr函数适用于其他的属性 */ </script> </html>