单元格中onclick可以插入一张图片吗? 我要实现的功能如下:在一个表格的单元格中单击,插入一张图片(不是改变单元格背景),图片带一个超级连接.如果再单击一个单元格,那么前面单击过的单元格恢复空白原样. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try this :<td onclick="aa(this)">var aa = function (obj){ this.innerHTML = "<img src=''>";} <style>#tab{ border:0px; border-collapse:collapse;.}#tab td{ height:50px; width:50px; border:1px solid red; cursor:hand;}</style><script>window.table_img_src="http://www.csdn.net/CSDN_Common_Header_Footer/Images/BiaoShi.gif";window.table_img_link="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010";window.onload=function(){ var tab=document.getElementById("tab"); window.tab=tab; var cells=tab.getElementsByTagName("td"); for(var i=0;i<cells.length;i++){ cells[i].onclick=cell_onclick; }}function cell_onclick(){ if(window.tab.focus_cell)window.tab.focus_cell.innerHTML=""; window.tab.focus_cell=this; var img = document.createElement("img"); img.src=window.table_img_src; var link = document.createElement("a"); link.href=window.table_img_link; link.appendChild(img); this.appendChild(link);}</script><table id="tab"><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr></table> if(window.tab.focus_cell)window.tab.focus_cell.innerHTML="";前面加一句:if(window.tab.focus_cell==this)return;不然会有bug~~ 大家帮我看看这行js有什么问题 二级导航内容重复显示 Javascript中最常用的20个经典技巧 用javascript往<select>标签里添加<option>有几种方法 求一正则表达式,将运算符之间的字符串提取出来 关于JavaScript调用XML属性的问题! 通过jscript怎样获取控件里的事件的参数? 是否JS写的代码封装的问题? 请问专家一个不是很难的问题! 两个js文件方法调用问题 javascript附值问题, 求高手帮帮忙! 有谁做过无刷新页面弹出类似msn消息框,并且是实时访问数据库的
this.innerHTML = "<img src=''>";}
#tab{
border:0px;
border-collapse:collapse;.
}
#tab td{
height:50px;
width:50px;
border:1px solid red;
cursor:hand;
}
</style>
<script>
window.table_img_src="http://www.csdn.net/CSDN_Common_Header_Footer/Images/BiaoShi.gif";
window.table_img_link="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010";
window.onload=function(){
var tab=document.getElementById("tab");
window.tab=tab;
var cells=tab.getElementsByTagName("td");
for(var i=0;i<cells.length;i++){
cells[i].onclick=cell_onclick;
}
}
function cell_onclick(){
if(window.tab.focus_cell)window.tab.focus_cell.innerHTML="";
window.tab.focus_cell=this;
var img = document.createElement("img");
img.src=window.table_img_src;
var link = document.createElement("a");
link.href=window.table_img_link;
link.appendChild(img);
this.appendChild(link);
}
</script>
<table id="tab">
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
</table>
前面加一句:
if(window.tab.focus_cell==this)return;不然会有bug~~