日期:2014-05-16  浏览次数:20309 次

在一个 <td class=" 我设置了一个背景">我点击文本框时<input type="text"><td/>改变我td的背景?

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.test{
background-color:#F00;
}
</style>
<script type="text/javascript">
function change(t,n){
var p=t.parentNode;
if(n==1){
p.className='';
t.className='test';
}else{
p.className='test';
t.className='';
}
}
</script>
</head>

<body>
<table>
<tr>
     <td class="test">test<input type="text" onclick="change(this,1)" onblur="change(this,0)"></td>
    </tr>
</table>
</body>
</html>
类似这样?
------解决方案--------------------
引用:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.test{
background-color:#F00;
}
</style>
<script type="text/javascript">
function change(t,n){
var p=t.parentNode;
if(n==1){
p.className='';
t.className='test';
}else{
p.className='test';
t.className='';
}
}
</script>
</head>

<body>
<table>
<tr>
     <td class="test">test<input type="text" onclick="change(this,1)" onblur="change(this,0)"></td>
    </tr>
</table>
</body>
</html>
类似这样?


借楼上的改改,是这样吗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.test{
border:1px solid red;
}
</style>
<script type="text/javascript">
function change(t,n){
if(n==1){
t.className='test';
}else{
t.className='';
}
}
</script>
</head>

<body>
<table>
<tr>
     <td>test<input type="text" onclick="change(this,1)" onblur="change(this,0)"></td>
    </tr>
</table>
</body>
</html>