测试

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>

 

posted on 2015-08-18 18:07  Q&A  阅读(95)  评论(0编辑  收藏  举报