JavaScript里面,节点创建不成功?
functionpreparePlaceholder(){if(!document.createElement)returnfalse;if(!document.crea...
function preparePlaceholder(){
if(!document.createElement) return false;
if(!document.createTextNode) return false;
if(!document.getElementById) return false;
if(!document.getElementById("imagegallery")) return false;
var placeholder=document.createElement("img");
placeholder.setAttribute("id","placeholder");
placeholder.setAttribute("src","images/1.jpg");
placeholder.setAttribute("alt","我仅仅只是个占位的");
var description=document.createElement("p");
description.setAttribute("id","description");
var desctext=document.createTextNode("choose an image");
description.appendChild(desctext);
var gallery=document.getElementById("imagegallery");
insertAfter(placeholder,gallery);
insertAfter(desctext,placeholder);
if(!document.getElementById("description")) return false;
console.log("成功创建description");
}
在控制台里面,那句“成功创建description”没有出来。看了好久觉得也没有错啊...
求问为什么0.0 展开
if(!document.createElement) return false;
if(!document.createTextNode) return false;
if(!document.getElementById) return false;
if(!document.getElementById("imagegallery")) return false;
var placeholder=document.createElement("img");
placeholder.setAttribute("id","placeholder");
placeholder.setAttribute("src","images/1.jpg");
placeholder.setAttribute("alt","我仅仅只是个占位的");
var description=document.createElement("p");
description.setAttribute("id","description");
var desctext=document.createTextNode("choose an image");
description.appendChild(desctext);
var gallery=document.getElementById("imagegallery");
insertAfter(placeholder,gallery);
insertAfter(desctext,placeholder);
if(!document.getElementById("description")) return false;
console.log("成功创建description");
}
在控制台里面,那句“成功创建description”没有出来。看了好久觉得也没有错啊...
求问为什么0.0 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询