function MiniKB(datanode, dispnode) { this._dispnode = dispnode; this._datanode = datanode; } //MiniKB.NONE = "清除"; //MiniKB.BACK = "后退"; //MiniKB.OK = "确认"; MiniKB.prototype.onchange = function () {}; MiniKB.prototype.create = function ( doc, order ) { if ( doc == null ) doc = document; if ( order == null ) order = "0123456789"; this._document = doc; this._order = order; // create elements this._el = doc.createElement( "div" ); this._el.className = "minikb"; var bodyTable = doc.createElement( "table" ); this._el.appendChild( bodyTable ); var tbody = doc.createElement( "tbody" ); bodyTable.appendChild(tbody); var tr = doc.createElement( "tr" ); tbody.appendChild(tr); var td = doc.createElement( "td" ); this._button0 = doc.createElement("button"); this._button0.className = "button" + order.charAt(0); this._button0.setAttribute("type", "button"); td.appendChild(this._button0); tr.appendChild(td); var td = doc.createElement( "td" ); this._button1 = doc.createElement("button"); this._button1.className = "button" + order.charAt(1); this._button1.setAttribute("type", "button"); td.appendChild(this._button1); tr.appendChild(td); var td = doc.createElement( "td" ); this._button2 = doc.createElement("button"); this._button2.className = "button" + order.charAt(2); this._button2.setAttribute("type", "button"); td.appendChild(this._button2); tr.appendChild(td); var td = doc.createElement( "td" ); this._button3 = doc.createElement("button"); this._button3.className = "button" + order.charAt(3); this._button3.setAttribute("type", "button"); td.appendChild(this._button3); tr.appendChild(td); var td = doc.createElement( "td" ); this._button4 = doc.createElement("button"); this._button4.className = "button" + order.charAt(4); this._button4.setAttribute("type", "button"); td.appendChild(this._button4); tr.appendChild(td); var td = doc.createElement( "td" ); this._backbutton = doc.createElement("button"); this._backbutton.className = "backbutton"; this._backbutton.setAttribute("type", "button"); //this._backbutton.appendChild(doc.createTextNode(MiniKB.BACK)); td.appendChild(this._backbutton); tr.appendChild(td); var tr = doc.createElement( "tr" ); tbody.appendChild(tr); var td = doc.createElement( "td" ); this._button5 = doc.createElement("button"); this._button5.className = "button" + order.charAt(5); this._button5.setAttribute("type", "button"); td.appendChild(this._button5); tr.appendChild(td); var td = doc.createElement( "td" ); this._button6 = doc.createElement("button"); this._button6.className = "button" + order.charAt(6); this._button6.setAttribute("type", "button"); td.appendChild(this._button6); tr.appendChild(td); var td = doc.createElement( "td" ); this._button7 = doc.createElement("button"); this._button7.className = "button" + order.charAt(7); this._button7.setAttribute("type", "button"); td.appendChild(this._button7); tr.appendChild(td); var td = doc.createElement( "td" ); this._button8 = doc.createElement("button"); this._button8.className = "button" + order.charAt(8); this._button8.setAttribute("type", "button"); td.appendChild(this._button8); tr.appendChild(td); var td = doc.createElement( "td" ); this._button9 = doc.createElement("button"); this._button9.className = "button" + order.charAt(9); this._button9.setAttribute("type", "button"); td.appendChild(this._button9); tr.appendChild(td); var td = doc.createElement( "td" ); this._clearbutton = doc.createElement("button"); this._clearbutton.className = "clearbutton"; this._clearbutton.setAttribute("type", "button"); //this._clearbutton.appendChild(doc.createTextNode(MiniKB.NONE)); td.appendChild(this._clearbutton); tr.appendChild(td); var tr = doc.createElement( "tr" ); tbody.appendChild(tr); td = doc.createElement( "td" ); td.colSpan = 5; td.className = "filler"; td.appendChild( doc.createTextNode( String.fromCharCode( 160 ) ) ); tr.appendChild(td); var td = doc.createElement( "td" ); this._okbutton = doc.createElement("button"); this._okbutton.className = "okbutton"; this._okbutton.setAttribute("type", "button"); //this._okbutton.appendChild(doc.createTextNode(MiniKB.OK)); td.appendChild(this._okbutton); tr.appendChild(td); // IE55+ extension this._backbutton.hideFocus = true; this._clearbutton.hideFocus = true; // end IE55+ extension // hook event var kb = this; this._button0.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(0)); }; this._button1.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(1)); }; this._button2.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(2)); }; this._button3.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(3)); }; this._button4.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(4)); }; this._button5.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(5)); }; this._button6.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(6)); }; this._button7.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(7)); }; this._button8.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(8)); }; this._button9.onclick = function () { kb.setData(kb.getData() + kb._order.charAt(9)); }; this._backbutton.onclick = function () { if (kb.getData().length == 0) return; kb.setData(kb.getData().substring(0, kb.getData().length - 1)); }; this._clearbutton.onclick = function () { if (kb.getData().length == 0) return; kb.setData(""); }; this._okbutton.onclick = function () { kb.close(); }; return this._el; } MiniKB.prototype.setData = function ( data ) { // need for ie if (this._datanode.maxLength > 0 && data.length > this._datanode.maxLength) return; this._datanode.value = data; } MiniKB.prototype.getData = function ( ) { return this._datanode.value; } MiniKB.prototype.close = function ( doc ) { this._dispnode.removeChild(this._el); } function ToggleMiniKB(datanode, dispnode, order) { if (dispnode.hasChildNodes()) { dispnode.removeChild(dispnode.childNodes[0]); }else{ var kb = new MiniKB(datanode, dispnode); dispnode.appendChild(kb.create(null, order)); } }