日期:2014-05-16 浏览次数:20344 次
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="lib.js"></script> <script type="text/javascript" src="FormView.js"></script> <script> // 测试 window.onload = function(){ var inputView = new FormInput('txt1'); inputView.setValue('world') //alert("input value:"+inputView.getValue()) var formRadio = new FormRadio('radioId'); var items = [{value:'1',text:'男'},{value:'0',text:'女'}] formRadio.setItems(items); formRadio.setValue(0); //alert("radio value:"+formRadio.getValue()) var fromCheckBox = new FormCheckBox('checkboxId'); var items2 = [{value:'1',text:'足球'},{value:'0',text:'篮球'}, {value:'2',text:'羽毛球'}] fromCheckBox.setItems(items2); fromCheckBox.setValue([1,2]); //alert(fromCheckBox.getValue()) var select = new FormSelect('selectId'); var selectItems = [{value:0,text:'上海'}, {value:1,text:'北京'},{value:2,text:'天津'}]; select.setItems(selectItems); select.setValue(1) //alert("select value:"+select.getValue()) var formTextArea = new FormTextArea('textAreaId'); formTextArea.setValue("<b>hello world</b>"); //alert("textarea value:"+formTextArea.getValue()); var controls = []; controls.push(inputView); controls.push(formRadio); controls.push(select); controls.push(fromCheckBox); controls.push(formTextArea); // 这里实现了接口的统一 for(var i in controls) { var control = controls[i]; alert(control.id + ": " + control.getValue()) } } </script> </head> <body> input <input id="txt1" value="hello"><br> radio <div id="radioId"></div><br> checkbox <div id="checkboxId"></div><br> select <select id="selectId"></select><br> textArea <textarea rows="3" cols="20" id="textAreaId"></textarea> </body> </html>
;(function() { var util = { /** * Usage: * * format('{y}年{m}月{d}日',{y:'2010',m:'09',d:'15'}); * return: 2010年09月15日 */ format:function(str,obj){ for(var key in obj){ str = str.replace(new RegExp("\\{" + key + "\\}", "g"), obj[key]); } return str; } }; var lib = { extend:function(subClass,superClass){ var F = function(){}; F.prototype = superClass.prototype; subClass.prototype = new F(); subClass.prototype.constructor = subClass; subClass.superclass = supe