javascript 怎么通过setAttribute 设置属性为元素对象

javascript 如何通过setAttribute 设置属性为元素对象
var popIcon = document.createElement("IMG");
popIcon.setAttribute("editor", objEdit);
上面面的代码,目的是将 objEdit对象(是一个文本框对象),绑定到popIcon的属性中,
后面的会通过调用popIcon的属性,获取绑定的objEdit对象。之前这段代码,在IE7或IE8下面可以运行。
或者在IE10的兼容模式下也可以运行,但是如果在IE10非兼容模式下,就会报错:“错误: 未指明的错误”
看看大家,有什么好的解决办法?谢谢。

------解决方案--------------------
例如:
var bar = document.getElementById(testbt);
bar.setAttribute(onclick, javascript:alert('This is a test!'););
这里利用setAttribute指定e的onclick属性,简单,很好理解。
但是IE不支持,IE并不是不支持setAttribute这个函数,而是不支持用setAttribute设置某些属性,例如对象属性、集合属性、事件属性,也就是说用setAttribute设置style和onclick这些属性在IE中是行不通的。

为达到兼容各种浏览器的效果,可以用点符号法来设置Element的对象属性、集合属性和事件属性。
document.getElementById(testbt).className = bordercss;
document.getElementById(testbt).style.cssText = color: #00f;;
document.getElementById(testbt).style.color = #00f;
document.getElementById(testbt).onclick= function () { alert(This is a test!); }

------解决方案--------------------
返回值:Anydata([name])
概述
返回元素上储存的相应名字的数据,可以用data(name, value)来设定。

如果jQuery集合指向多个元素,那将只返回第一个元素的对应数据。 

这个函数可以用于在一个元素上存取数据而避免了循环引用的风险。jQuery.data是1.2.3版的新功能。你可以在很多地方使用这个函数,另外jQuery UI里经常使用这个函数。 

如果不带任何参数,则会把所有数据作为一个JavaScript对象来返回。

参数
name (可选)String存储的数据名

示例
描述:
在一个div上存取数据

HTML 代码:
<div></div>jQuery 代码:
$("div").data("blah");  // undefined
$("div").data("blah", "hello");  // blah设置为hello
$("div").data("blah");  // hello
$("div").data("blah", 86);  // 设置为86
$("div").data("blah");  //  86
$("div").removeData("blah");  //移除blah
$("div").data("blah");  // undefined描述:
在一个div上存取名/值对数据

HTML 代码:
<div></div>jQuery 代码:
$("div").data("test", { first: 16, last: "pizza!" });
$("div").data("test").first  //16;
$("div").data("test").last  //pizza!;
------解决方案--------------------
var popIcon = document.createElement("IMG");
popIcon本身是一个对象,可以直接添加属性,如popIcon.a={a:1}
------解决方案--------------------
popIcon.setAttribute("editor", inputeditor);   高版本!=    popIcon.editor=inputeditor.

所以你直接
popIcon.editor=inputeditor.就可以。