日期:2014-05-17  浏览次数:20772 次

请教如何使用CSS让TD标签内不管有没有内容都包含一个输入框,谢谢
<html>

<head> 

<script>

window.onload = function(){

var obj = document.getElementsByTagName("td");

for(var i=0;i<obj.length;i++){

if(i%4==0)obj[i].className="a"

if(i%4==1)obj[i].className="b"

if(i%4==2)obj[i].className="c"

if(i%4==3)obj[i].className="d"

}

};

</script>

<style> 

.a {color:#A00;}

.b {color:#0B0;}

.c {color:#00C;}

.d {color:#D00;}

</style>

</head>

<body>

<table border=1>

<tr><td style= "width:600;word-break:break-all "> 
a</td><td>b</td></tr>

<tr><td>c</td><td style= "width:600;word-break:break-all ">d</td></tr>

<tr><td>e</td><td></td></tr>

<tr><td>g</td><td>h</td></tr>

</table>

</body>

</html>



------解决方案--------------------
<script>

window.onload = function(){

var obj = document.getElementsByTagName("td");

for(var i=0;i<obj.length;i++){

if(i%4==0)obj[i].className="a"

if(i%4==1)obj[i].className="b"

if(i%4==2)obj[i].className="c"

if(i%4==3)obj[i].className="d"

}
for(x in obj) {
obj[x].innerHTML+="<input type='text' />";
};
};

</script>