Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. function Element (name, template, type) {
  2. this.name = name;
  3. this.classes = ["formClass"];
  4. this.template = template;
  5. };
  6. // debugger;
  7. function InputElement (name, template, type) {
  8. Element.call(this);
  9. this.type = type;
  10. };
  11. Element.prototype.draw = function (parentElement) {
  12. $Element = $(this.template);
  13. $Element.attr("name", this.name);
  14. $Element.addClass(this.classes.join(""));
  15. $Element.attr("type",)
  16. $(parentElement).prepend($Element);
  17. return $Element;
  18. };
  19.  
  20. var testForm = new Element("form", "<form></form>");
  21. var testInput = new Element("input", "<input></input>", "password");
  22. testForm.draw("body");
  23. testInput.draw("form");
  24.  
  25. function Element (template, attributes) {
  26. if(typeof attributes === "object") {
  27. for( var prop in attributes) {
  28. this[prop] = attributes[prop];
  29. }
  30. }
  31. this.template = template || "<div/>"; // по умолчанию div
  32. };
  33.  
  34. // создавать элементв в prototype.draw:
  35. $Element = $(this.template, this.attributes);
  36.  
  37. // и вызывать:
  38. var testForm = new Element("<form/>", {name: "form"});
  39. var testInput = new Element("<input/>", {name:"form", type:"password"});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement