为什么图片显示不了

it_sql 2009-03-11 09:29:21

var cell =document.createElement("td");
cell.setAttribute("style","cursor:pointer" );
cell.setAttribute("height","250px" );
cell.setAttribute("valign","top" );
var t=document.createElement("table");
t.setAttribute("width","218");
t.setAttribute("border","0");
t.setAttribute("cellpadding","0");
t.setAttribute("cellspacing","0");
t.setAttribute("onmouseover",function(){this.style.backgroundColor="#CBE83E"});
t.setAttribute("onmouseout",function(){this.style.backgroundColor="#FFFFFF"});
var row=document.createElement("tr")
var cell1 =document.createElement("td");
var a=document.createElement("a");
a.setAttribute("href","show?id="+text);
a.setAttribute("target","_blank");
var img1 =document.createElement("img");
img1.setAttribute("src",text2);
a.appendChild(img1);
cell1.appendChild(a);//
row.appendChild(cell1);
t.appendChild(row);//
var row1=document.createElement("tr")
var cell2 =document.createElement("td");
cell2.setAttribute("height","60");
cell2.setAttribute("width","100%");
cell2.setAttribute("align","right");
cell2.setAttribute("class","photoTitle");
var divc =document.createElement("div") //创建一个DIV一个节点
var tableNode=document.createTextNode(text1); //创建一个文本节点
var a1=document.createElement("a")
a1.setAttribute("href","show?id"+text);
a1.setAttribute("target","_blank");
var f=document.createElement("font")//创建一个字节点
f.setAttribute("face","Arial");
f.appendChild(tableNode);
a1.appendChild(f);
divc.appendChild(a1);
cell2.appendChild(divc);//把文本赋值给cell
cell2.setAttribute("class","photoTitle");
row1.appendChild(cell2);
t.appendChild(row1);//
cell.appendChild(t);//
alert(text2);
alert(cell.outerHTML);
return cell;

为什么没有图片显示?图片的路径是对的.
...全文
55 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gengzhw 2009-03-12
  • 打赏
  • 举报
回复
可以显示,不过调试时有点错误,比较一下吧:
<p id=mp></p>
<script type="text/javascript">
var text = '987',text1='page.987',text2='http://www.csdn.net/Images/logo_csdn.gif';

var cell =document.createElement("td");
cell.setAttribute("style","cursor:pointer" );
cell.setAttribute("height","250px" );
cell.setAttribute("valign","top" );
var t=document.createElement("table");
t.setAttribute("width","218");
t.setAttribute("border","0");
t.setAttribute("cellpadding","0");
t.setAttribute("cellspacing","0");
t.setAttribute("onmouseover",function(){this.style.backgroundColor="#CBE83E"});
t.setAttribute("onmouseout",function(){this.style.backgroundColor="#FFFFFF"});
var row=document.createElement("tr")
var cell1 =document.createElement("td");
var a=document.createElement("a");
a.setAttribute("href","show?id="+text);
a.setAttribute("target","_blank");
var img1 =document.createElement("img");
img1.setAttribute("src",text2);
a.appendChild(img1);
cell1.appendChild(a);//
row.appendChild(cell1);
t.appendChild(row);//
var row1=document.createElement("tr")
var cell2 =document.createElement("td");
cell2.setAttribute("height","60");
cell2.setAttribute("width","100%");
cell2.setAttribute("align","right");
cell2.setAttribute("class","photoTitle");
var divc =document.createElement("div"); //创建一个DIV一个节点
var tableNode=document.createTextNode(text1); //创建一个文本节点
var a1=document.createElement("a")
a1.setAttribute("href","show?id"+text);
a1.setAttribute("target","_blank");
var f=document.createElement("font")//创建一个字节点
f.setAttribute("face","Arial");
f.appendChild(tableNode);
a1.appendChild(f);
divc.appendChild(a1);
cell2.appendChild(divc);//把文本赋值给cell
cell2.setAttribute("class","photoTitle");
row1.appendChild(cell2);
t.appendChild(row1);//
cell.appendChild(t);//
alert(text2 +'\n\n'+ cell.outerHTML);
// return cell;

document.getElementById('mp').innerHTML = cell.outerHTML;

</script>
esena 2009-03-11
  • 打赏
  • 举报
回复
图片改成绝对路径试试,我这边用绝对路径测试可以正常显示,能显示之后再调试相对路径

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧