Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Element (name, template, type) {
- this.name = name;
- this.classes = ["formClass"];
- this.template = template;
- };
- // debugger;
- function InputElement (name, template, type) {
- Element.call(this);
- this.type = type;
- };
- Element.prototype.draw = function (parentElement) {
- $Element = $(this.template);
- $Element.attr("name", this.name);
- $Element.addClass(this.classes.join(""));
- $Element.attr("type",)
- $(parentElement).prepend($Element);
- return $Element;
- };
- var testForm = new Element("form", "<form></form>");
- var testInput = new Element("input", "<input></input>", "password");
- testForm.draw("body");
- testInput.draw("form");
- function Element (template, attributes) {
- if(typeof attributes === "object") {
- for( var prop in attributes) {
- this[prop] = attributes[prop];
- }
- }
- this.template = template || "<div/>"; // по умолчанию div
- };
- // создавать элементв в prototype.draw:
- $Element = $(this.template, this.attributes);
- // и вызывать:
- var testForm = new Element("<form/>", {name: "form"});
- var testInput = new Element("<input/>", {name:"form", type:"password"});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement