主页  
     分类  
     关于  
 
    
        
          
  JavaScript DOM 
  
      
      JavaScript个人整理 
操作DOM对象 获得DOM节点 浏览器网页就是一个DOM树形结构 
"Syp" ><h1 > 实验品</h1 > <p  id ="Reuben" > 鲁本</p > <p  class ="Angel" > 安琪</p > <p  id ="Stitch" > 史迪奇</p > <script >          var  h1 = document .getElementsByTagName ("h1" )     var  Reuben  = document .getElementById ("Reuben" )     var  Angel  = document .getElementByclassName ("Angel" )     var  Stitch  = document .getElementById ("Stitch" )          var  childrens = Syp .hildrens ;           </script > 
更新DOM节点 "Syp" ><h1 > 实验品</h1 > <p  id ="Reuben" > 鲁本</p > <p  class ="Angel" > 安琪</p > <p  id ="Stitch" > 史迪奇</p > <script >     var  Syp  = document .getElementById ("Syp" ) </script > 
操作文本 Syp .innerText  = '我叫史迪奇' ;Syp .innerHTML  = '<strong>我叫史迪奇</strong>' ;
操作css Syp .style .color  = 'blue' ;Syp .style .fontSize  = '333px' ;Syp .style .padding  = '3em' ;
删除节点 步骤: 先获取父节点, 再获取子节点, 然后通过父节点删除子节点 
<div id="Syp" ><h1 > 实验品</h1 > <p  id ="Reuben" > 鲁本</p > <p  class ="Angel" > 安琪</p > <p  id ="Stitch" > 史迪奇</p > <script >          var  Syp  = Reuben .parentElement ;          var  Reuben  = document .getElementById ("Reuben" )          Syp .removeChild (Reuben )          Syp .removeChild (Syp .children [0 ]) </script > 
插入DOM节点 <p id="Syp" >实验品</p><div  id ="list" >     <p  id ="Reuben" > 鲁本</p >      <p  id ="Angel" > 安琪</p >      <p  id ="Stitch" > 史迪奇</p >  </div > <script >     var  Syp  = document .getElementById ("Syp" )     var  list = document .getElementById ("list" ) </script > 
然后浏览器输入来实现 追加效果 
// 追加
创建DOM新节点 <p id="Syp" >实验品</p><div  id ="list" >     <p  id ="Reuben" > 鲁本</p >      <p  id ="Angel" > 安琪</p >      <p  id ="Stitch" > 史迪奇</p >  </div > <script >     var  Syp  = document .getElementById ("Syp" )     var  list = document .getElementById ("list" )          var  sdq = document .createRlement ("p" )          sdq.id  = "sdq"           sdq.innerText  = "我叫史迪奇"      list.appendChild  </script > 
然后浏览器输入来实现 创建效果 
// 创建
创建一个script标签节点 <p id="Syp" >实验品</p><div  id ="list" >     <p  id ="Reuben" > 鲁本</p >      <p  id ="Angel" > 安琪</p >      <p  id ="Stitch" > 史迪奇</p >  </div > <script >     var  Syp  = document .getElementById ("Syp" )     var  list = document .getElementById ("list" )     var  sdq = document .createRlement ("p" )     sdq.id  = "sdq"      sdq.innerText  = "我叫史迪奇"           var  script = document .createRlement ("script" );     script.setAttribute ('type' ,'text/javascript' ) </script > 
然后浏览器输入来实现 创建效果 
// 创建
创建一个script标签节点 <p id="Syp" >实验品</p><div  id ="list" >     <p  id ="Reuben" > 鲁本</p >      <p  id ="Angel" > 安琪</p >      <p  id ="Stitch" > 史迪奇</p >  </div > <script >     var  Syp  = document .getElementById ("Syp" )     var  list = document .getElementById ("list" )     var  sdq = document .createRlement ("p" )     sdq.id  = "sdq"      sdq.innerText  = "我叫史迪奇"           var  style = document .createRlement ("style" );     style.setAttribute ('type' ,'text/css' );          style.innerHTML  = 'body{background-color: chartreuse;}'       </script > 
然后浏览器输入来实现 创建效果 
// 创建style
操作表单 (验证) 
文本框 text 
下拉框  
单选框 radio 
多选框 checkbox 
隐藏域 hidden 
密码框  password 
 
获得提交的信息 <form action="list" >
然后浏览器输入来实现 创建效果 
// 得到输入框的值
 以下为效果 
    实验品编号:  
    
    
        实验品编号:  
        
  
提交表单 <!-- MD5  工具类 --><script  src ="https:cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js" > </script > 
 以下为效果 
 
    
 
  作者: 我叫史迪奇
  https://sdq3.link/JavaScript-DOM.html 博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议