<html>
<head>
<script type="text/javascript" src="admin/js/jquery.min.js"></script>
<body>
<table id="c1" width="98%" border="1px" cellspacing="0" cellpadding="0" >
<tr>
<td><input name="t1" value="aa1" /></td>
<td id="c2">2</td>
<td>3</td>
</tr>
<tr>
<td><input class="test1" id="test1" border="1px" onkeypress="demo1()" type="text" /></td>
<td><input class="test1" id="test2" onkeypress="demo1()" type="text" /></td>
<td><input class="test1" id="test3" onkeypress="demo1()" type="text" /></td>
</tr>
<tr>
<td>dd</td>
<td>dd</td>
<td>dd</td>
</tr>
<tr>
<td>dd</td>
<td>dd</td>
<td>dd</td>
</tr>
</table>
</body>
<script>
//jQuery代码
function demo1() {
//var dd = document.getElementsByName(‘t1‘)[0].value;//通过名字,得到input中值,遍历是从0开始的
//var testLength = document.getElementById(‘test1‘).value.length;
var testLength = document.getElementById("c1").rows[0].cells[0].offsetWidth; //表格中id,table中第一行 第一列
alert("宽度为:" + testLength);
$(‘.test1‘).css(‘width‘, testLength*5 + ‘px‘)//点表类,#表id 动态设置input框长度
}
</script>
</html>