Created
April 28, 2013 04:52
-
-
Save QETHAN/5475936 to your computer and use it in GitHub Desktop.
创建元素 SeaJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 创建元素 | |
*/ | |
define(function(require, exports) { | |
exports.create = function(tagName, attr) { | |
var element = null; | |
if (typeof tagName === "string") { | |
element = document.createElement(tagName); | |
if (typeof attr === "object") { | |
var keyAttr, keyStyle; | |
for (keyAttr in attr) { | |
if (keyAttr === "styles" && typeof attr[keyAttr] === "object") { | |
// 样式们 | |
for (keyStyle in attr[keyAttr]) { | |
element.style[keyStyle] = attr[keyAttr][keyStyle]; | |
if (keyStyle === "opacity" && window.innerWidth + "" == "undefined") { | |
element.style.filter = "alpha(opacity="+ (attr[keyAttr][keyStyle] * 100) +")"; | |
} | |
} | |
} else { | |
if (keyAttr === "class") { | |
keyAttr = "className"; | |
} | |
element[keyAttr] = attr[keyAttr]; | |
} | |
} | |
} | |
} | |
return element; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment