object.setAttribute(sName, vValue [, iFlags])
参数:
sName
必填项. String类型,属性名vValue
必填项. 为属性指定的变量,可以为string, number, 或者 Boolean类型iFlags
选填. 下面指定的两种 Integer 类型的标志0
覆盖同名属性.1
默认值. 为属性添加指定的值.
实力
<html>
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.TableLine
{
border-collapse: collapse;
border: 1px solid #9BC2E0;
}
.TableLine td
{
border: 1px solid #9BC2E0;
}
</style>
<script type="text/javascript">
function a(){
document.getElementById("td_ID").setAttribute("colspan","2",0); //成功
//document.getElementById("td_ID").setAttribute("colspan","2"); 失败
}
</script>
</head>
<body onload="a()">
<form id="form1" runat="server">
<table id="TableID" class="TableLine">
<tr>
<td>
1
</td>
<td>
2
</td>
</tr>
<tr>
<td id="td_ID">
dasfasfd
</td>
</tr>
<tr>
<td colspan="2">
d
</td>
</tr>
</table>
</form>
</body>
</html>