⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 create.js

📁 这是《JavaScript学习源代码》一书的源代码
💻 JS
字号:
// declare global variables
var pic, tag, target;

// a function to create and append HTML element objects
function append()
{
  if (!pic) 	
  {
    // create a new img element
    pic = window.document.createElement("img");		  
    pic.setAttribute("src","deedee.gif");
  }
 
  if(!tag)
  {
    // create a new span element
    tag = window.document.createElement("span");		
    var lbl = window.document.createTextNode("Hi Everyone!");
    tag.appendChild(lbl);
  }

    // specify an existing element to append new elements 
    target = window.document.getElementById("para");  
    target.appendChild(pic);
    target.appendChild(tag);
}


// a function to remove appended HTML objects
function remove()
{

  if(target.hasChildNodes()) 				
  {
    target.removeChild(pic);
    target.removeChild(tag);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -