您的位置:首页 > 其它

测试

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: