---
title: "IE处理setAttribute无效问题"
author: "slendersEye"
date: "2013-05-01T20:50:29Z"
tags: ["setAttribute", "无效"]
categories: ["Web前端"]
slug: "ie-setattribute"
draft: false
lastmod: "2013-05-01T20:57:31Z"
id: 1858221
url: "https://sleepyy.iteye.com/blog/1858221"
---

ie下，用js setAttribute设置table属性不起作用，比如 cellspacing, rowspan， colspan等，

问题根源是，ie在解析时，取的属性值是 cellSpacing, rowSpan， colSpan，而非全小写的形式。

 

IE解析出的真实DOM树可F12进调试模式查看

 

解决办法很简单，多写一行直接属性赋值：

```
			tdFirst.setAttribute("colspan", colspan);
			tdFirst.colSpan = colspan;
```