测试
2015-08-18 18:07
323 查看
cardList = [];
cardList.AddData = function (data) {
this[this.length] = data;
}
cardList.DelData = function (id) {
// for (var i = id; i < this.length - 1; i++) {
// this[i] = this[i + 1];
// }
this.length--;
}
function getElement(id) {
return document.getElementById(id);
};
function getElementByName(name) {
return document.getElementsByName(name);
};
window.onload = function () {
getElement("btnAdd").onclick = function () {
var data = getElement("txtCard").value;
var tmpRow = getElement("rowTmp").childNodes[0].cloneNode(true);
tmpRow.childNodes[0].innerHTML = data; //getElement("context").childNodes.length + 1;
getElement("context").appendChild(tmpRow);
cardList.AddData(data);
getElement("txtCard").value = "";
getElement("txtCard").focus();
};
getElement("btnDel").onclick = function () {
var context = getElement("context");
if (context.lastChild) {
context.removeChild(context.lastChild);
cardList.DelData();
}
};
getElement("btnOK").onclick = function () {
alert(cardList);
};
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="js/Test.js"></script>
</head>
<body>
<div>
<input type="text" id="txtCard" value="" />
<button id="btnAdd">
+</button>
<button id="btnDel">
-</button>
</div>
<div id="context">
</div>
<div>
<button id="btnOK">
OK</button>
<button id="btnCancel">
Cancel</button>
</div>
<div id="rowTmp" style="display: none">
<div>
<label>
</label>
</div>
</div>
</body>
</html>
cardList.AddData = function (data) {
this[this.length] = data;
}
cardList.DelData = function (id) {
// for (var i = id; i < this.length - 1; i++) {
// this[i] = this[i + 1];
// }
this.length--;
}
function getElement(id) {
return document.getElementById(id);
};
function getElementByName(name) {
return document.getElementsByName(name);
};
window.onload = function () {
getElement("btnAdd").onclick = function () {
var data = getElement("txtCard").value;
var tmpRow = getElement("rowTmp").childNodes[0].cloneNode(true);
tmpRow.childNodes[0].innerHTML = data; //getElement("context").childNodes.length + 1;
getElement("context").appendChild(tmpRow);
cardList.AddData(data);
getElement("txtCard").value = "";
getElement("txtCard").focus();
};
getElement("btnDel").onclick = function () {
var context = getElement("context");
if (context.lastChild) {
context.removeChild(context.lastChild);
cardList.DelData();
}
};
getElement("btnOK").onclick = function () {
alert(cardList);
};
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="js/Test.js"></script>
</head>
<body>
<div>
<input type="text" id="txtCard" value="" />
<button id="btnAdd">
+</button>
<button id="btnDel">
-</button>
</div>
<div id="context">
</div>
<div>
<button id="btnOK">
OK</button>
<button id="btnCancel">
Cancel</button>
</div>
<div id="rowTmp" style="display: none">
<div>
<label>
</label>
</div>
</div>
</body>
</html>
相关文章推荐
- 详解CSS3中使用gradient实现渐变效果的方法
- RESTful架构详解
- “IE浏览器不支持在css文件中设定的dialog宽度”解决方法
- 引导选择失败
- IT痴汉的工作现状41-亲历招投标
- Codeforces Gym 100650B Countdown (离线)
- libcurl源码编译
- Leetcode#72||Edit Distance
- puppet进阶指南——service资源详解
- puppet进阶指南——service资源详解
- MySQL存储过程从另外两个表中取数据存整合其他数据保存在一张新的表里
- position:fixed失效的问题
- 一个让人痛苦想删不敢的文件夹winsxx
- Linux下boost安装、测试教程
- POI批量导出数据
- C#访问Azure的资源
- php -- 修改字符串的编码格式
- DNA Sorting 1007 (字符串排序)
- hadoop 统计输入的行数的MAP
- 多层高速PCB布线总结