<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>prototype</title> <script type="text/javascript"> window.onload = function (){
/*
var addNum = function (n1,n2){
this.num1 = n1;
this.num2 = n2;
this.add();
} addNum.prototype = {
add:function(){ //return this.num1 + this.num2;
alert(this.num1 + this.num2);
}
} var n = new addNum(3,4);
//alert(n.add());
*/ var createItems = function (){
this.oBtn = document.getElementById("btn");
this.oName = document.getElementById("tagName");
this.oValue = document.getElementById("tagValue");
this.tag = this.oName.value;
this.val = this.oValue.value;
var _this = this;
this.oBtn.onclick = function (){
//console.log(this.tag + " , " + this.val + " , " + this);
_this.create(_this);
}
}
createItems.prototype = {
create:function(_this){
alert(this.tag);
_this.nTag = document.createElement(_this.tag);
_this.nTag.innerHTML = _this.val;
document.body.appendChild(_this.nTag);
}
}
var c = new createItems();
}
</script> </head>
<body>
<input type="text" name="tagName" id="tagName" style="width:50px;" value="" />
<input type="text" name="tagValue" id="tagValue" value="" />
<input type="button" value="点击" name="btn" id="btn" /> </body>
</html>

  • 错的
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>prototype</title> <script type="text/javascript"> window.onload = function (){
/*
var addNum = function (n1,n2){
this.num1 = n1;
this.num2 = n2;
this.add();
} addNum.prototype = {
add:function(){ //return this.num1 + this.num2;
alert(this.num1 + this.num2);
}
} var n = new addNum(3,4);
//alert(n.add());
*/ var createItems = function (){
this.oBtn = document.getElementById("btn");
this.oName = document.getElementById("tagName");
this.oValue = document.getElementById("tagValue");
var _this = this;
this.oBtn.onclick = function (){
_this.create();
}
}
createItems.prototype = {
create:function(){
this.tag = this.oName.value;
this.val = this.oValue.value;
this.nTag = document.createElement(this.tag);
this.nTag.innerHTML = this.val;
document.body.appendChild(this.nTag);
}
}
var c = new createItems();
}
</script> </head>
<body>
<input type="text" name="tagName" id="tagName" style="width:50px;" value="" />
<input type="text" name="tagValue" id="tagValue" value="" />
<input type="button" value="点击" name="btn" id="btn" /> </body>
</html>

  • 对的

prototype入门----自定义创建元素的更多相关文章

  1. 无废话Android之listview入门,自定义的数据适配器、采用layoutInflater打气筒创建一个view对象、常用数据适配器ArrayAdapter、SimpleAdapter、使用ContentProvider(内容提供者)共享数据、短信的备份、插入一条记录到系统短信应用(3)

    1.listview入门,自定义的数据适配器 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and ...

  2. Sandcastle入门:创建C#帮助文档

    Sandcastle入门:创建C#帮助文档 今天学到了一个东西:利用vs2005生成的dll/xml来生成帮助文档. 完成这个伟大任务的是Sandcastle,微软推出的类库文档编译工具. 在开始这篇 ...

  3. React.js入门笔记 创建hello world 的6种方式

    一.ReactJS简介 React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写一套,用来架设 Instagram 的网站. ...

  4. SpringMVC基础入门,创建一个HelloWorld程序

    ref:http://www.admin10000.com/document/6436.html 一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要 ...

  5. XamarinAndroid组件教程设置自定义子元素动画(一)

    XamarinAndroid组件教程设置自定义子元素动画(一) 如果在RecyclerViewAnimators.Animators中没有所需要的动画效果,就可以自定义一个.此时,需要让自定义的动画继 ...

  6. jQuery3动画+创建元素

    一.jQuery的动画 1.jQuery自带的动画 1>变化的是width height opacity display <!DOCTYPE html> <html lang= ...

  7. 【WPF学习】第六十八章 自定义绘图元素

    上一章分析了WPF元素的内部工作元素——允许每个元素插入到WPF布局系统的MeasureOverride()和ArrangeOverride()方法中.本章将进一步深入分析和研究元素如何渲染自身. 大 ...

  8. HashSet存储自定义类型元素和LinkedHashSet集合

    HashSet集合存储自定义类型元素 HashSet存储自定义类型元素 set集合报错元素唯一: ~存储的元素(String,Integer,-Student,Person-)必须重写hashCode ...

  9. [MISSAJJ原创]cell内 通过SDWebImage自定义创建动态菊花加载指示器

    最后更新已经放到了github上了 MISSAJJ自己写的一个基于SDWebImage自定义的管理网络图片加载的工具类(普通图片加载,渐现Alpha图片加载,菊花Indicator动画加载) 经常在项 ...

随机推荐

  1. opencv python:直线检测 与 圆检测

    霍夫直线变换介绍 霍夫圆检测 现实中: example import cv2 as cv import numpy as np # 关于霍夫变换的相关知识可以看看这个博客:https://blog.c ...

  2. Android学习05

    AlertDialog(对话框) 它也是其他 Dialog的的父类!比如ProgressDialog,TimePickerDialog等,而AlertDialog的父类是:Dialog! AlertD ...

  3. 学习笔记(22)- plato-训练端到端的模型

    原始文档 Train an end-to-end model To get started we can train a very simple model using Ludwig (feel fr ...

  4. finally语句块一定会被执行吗

    finally语句块一定会被执行吗? 答案: 不一定 1. 发生异常的代码必须在try 代码块中,才有可能被执行 public class MyTest { public static void ma ...

  5. NAT穿透的详细讲解及分析

    原文地址:http://bbs.pediy.com/thread-131961.htm 一.什么是NAT?为什么要使用NAT?NAT是将私有地址转换为合法IP地址的技术,通俗的讲就是将内网与内网通信时 ...

  6. Java入门笔记 05-多线程

    介绍:Java提供了非常优秀的多线程支持,程序可以通过非常简单的方式来启动多线程.本章主要内容为:多线程的创建.启动.控制以及同步操作,并介绍JDK 5新增的线程创建方式. 一.线程的创建与使用: 1 ...

  7. Springboot学习:SpringMVC自动配置

    Spring MVC auto-configuration Spring Boot 自动配置好了SpringMVC 以下是SpringBoot对SpringMVC的默认配置:==(WebMvcAuto ...

  8. 批处理执行Testng

    @echo off set LIB=项目的jar路径 set CLASSPATH=%LIB%\jar\commons-beanutils-.jar;%LIB%\jar\testng.jar;%LIB% ...

  9. Spring Boot JDBC 使用教程

    总是要用到数据库的嘛,曾经我一度以为,写代码,编程就是搞数据库增删改查,甚至你设计一个系统,大部分时候在为如何设计关系型数据库努力,究其原因,是因为关系型数据库是逻辑的主要呈现. 这个系列,主要是对 ...

  10. 页面分享功能,分享好友、朋友圈判断,用share_type做标记 这里用的是jweixin-1.3.2.js

    这里用的是jweixin-1.3.2.js trigger: function (res) { //判断分享的状态,好友.朋友圈 localStorage.setItem("share_ty ...