prototype入门----自定义创建元素
<!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入门----自定义创建元素的更多相关文章
- 无废话Android之listview入门,自定义的数据适配器、采用layoutInflater打气筒创建一个view对象、常用数据适配器ArrayAdapter、SimpleAdapter、使用ContentProvider(内容提供者)共享数据、短信的备份、插入一条记录到系统短信应用(3)
1.listview入门,自定义的数据适配器 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and ...
- Sandcastle入门:创建C#帮助文档
Sandcastle入门:创建C#帮助文档 今天学到了一个东西:利用vs2005生成的dll/xml来生成帮助文档. 完成这个伟大任务的是Sandcastle,微软推出的类库文档编译工具. 在开始这篇 ...
- React.js入门笔记 创建hello world 的6种方式
一.ReactJS简介 React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写一套,用来架设 Instagram 的网站. ...
- SpringMVC基础入门,创建一个HelloWorld程序
ref:http://www.admin10000.com/document/6436.html 一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要 ...
- XamarinAndroid组件教程设置自定义子元素动画(一)
XamarinAndroid组件教程设置自定义子元素动画(一) 如果在RecyclerViewAnimators.Animators中没有所需要的动画效果,就可以自定义一个.此时,需要让自定义的动画继 ...
- jQuery3动画+创建元素
一.jQuery的动画 1.jQuery自带的动画 1>变化的是width height opacity display <!DOCTYPE html> <html lang= ...
- 【WPF学习】第六十八章 自定义绘图元素
上一章分析了WPF元素的内部工作元素——允许每个元素插入到WPF布局系统的MeasureOverride()和ArrangeOverride()方法中.本章将进一步深入分析和研究元素如何渲染自身. 大 ...
- HashSet存储自定义类型元素和LinkedHashSet集合
HashSet集合存储自定义类型元素 HashSet存储自定义类型元素 set集合报错元素唯一: ~存储的元素(String,Integer,-Student,Person-)必须重写hashCode ...
- [MISSAJJ原创]cell内 通过SDWebImage自定义创建动态菊花加载指示器
最后更新已经放到了github上了 MISSAJJ自己写的一个基于SDWebImage自定义的管理网络图片加载的工具类(普通图片加载,渐现Alpha图片加载,菊花Indicator动画加载) 经常在项 ...
随机推荐
- Spring IoC(一)bean实例化和依赖注入
1.IoC容器概述 IoC 全称为 Inversion of Control,翻译为 “控制反转”,它还有一个别名为 DI(Dependency Injection),即依赖注入. 所谓 IOC ,就 ...
- openresty-component
1.Array Var Nginx Module ArrayVarNginxModulelocation /foo { array_split ',' $arg_files to=$array; # ...
- SDNU_ACM_ICPC_2020_Winter_Practice_1st
A Petya is a big fan of mathematics, esecially its part related to fractions. Recently he learned th ...
- Genetic Algorithm 资源
算法源码: NeuralGenetic : https://github.com/ahmedfgad/NeuralGenetic evolving-simple-organisms : https:/ ...
- 计算机二级-C语言-程序设计题-190111记录-两种指针赋值的不同,普通输入输出函数和文件输入输出函数的使用
//程序设计题:函数fun的功能是:将两位数的正整数a,b合并形成一个整数放在c中.合并的方式是:将a数的十位和个位数依次放在c数的个位和百位上,b数的十位和个位数依次放在c数的十位和千位上.例如:当 ...
- java.lang.NoClassDefFoundError异常处理
1.异常信息: Caused by: java.lang.NoClassDefFoundError: com/pingan/cfss/monitor/user/controller/UserInfoC ...
- Introducing .NET 5
Today, we’re announcing that the next release after .NET Core 3.0 will be .NET 5. This will be the n ...
- 【C#】图解如何添加引用using MySql.Data.MySqlClient;
使用C#连接MySQL时,经常会用到命名空间using MySql.Data.MySqlClient; 这说明VS中没有添加引用,解决方法如下: 1,可点击以下两个链接的其中任何一个,下载MySQL. ...
- XCOJ 1008: 级数求和
1008: 级数求和 题目描述 已知:Sn= 1+1/2+1/3+…+1/n.显然对于任意一个整数K,当n足够大的时候,Sn大于K.现给出一个整数K(1<=k<=15),要求计算出一个最小 ...
- 【原】简单shell练习(五)
1.查询一个文件中某个单词出现的次数 # grep -o 'ts' ./test/txt |wc -l 2.统计当前文件夹下文件的个数 ls -l |grep "^-"|wc -l ...