例如:
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!); }
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!); }
概述
返回元素上储存的相应名字的数据,可以用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!;
popIcon本身是一个对象,可以直接添加属性,如popIcon.a={a:1}
var inputeditor = document.getElementById("editor");
var popIcon = document.createElement("IMG");
popIcon.setAttribute("src", _popImage);
popIcon.src= _popImage;
popIcon.setAttribute("editor", inputeditor);
popIcon.style.cssText = "Z-INDEX: 999; POSITION: absolute; display:none;";
popIcon.setAttribute("fi_attrib", "fi_popIcon");
popIcon.setAttribute("border", "0");
popIcon.setAttribute("onclick", "return _popIcon_onclick();");谢谢大家的支持,我把我的思路再明确下,红色字体部分是关键。
就是要把inputeditor 控件作为属性,赋值给popIcon。现在的问题是IE10以上,不兼容了。如何处理。谢谢。
如果JQUERY可以实现,也可以。
popIcon.editor=inputeditor.就可以。