一、大方法中包含小方法:
- <script type="text/javascript">
- function animal(){
- this.dog = function(){
- if(document.getElementById("username").value == ""){
- alert("hi,I'm dog.");
- }
- }
- this.cat = function(){
- if(document.getElementById("password").value == ""){
- alert("hi,I'm cat.");
- }
- }
- }
- new register().dog(); //调用方法
- </script>
二、定义域:
var baseControl = {
add : function() {
alert("I'm adding");
},
del : function() {
alert("I'm deleting");
},
edit : function() {
alert("I'm editing");
},
query : function() {
alert("I'm quering");
},
view : function(custid) {
alert("I'm viewing");
},
export2Xls : function() {
alert("I'm exporting");
}
};
本文介绍了一种使用JavaScript进行方法封装的技术,通过构造函数和对象字面量的方式实现不同功能的方法组合。同时展示了如何在这些方法中进行条件判断以实现特定的功能,如检查表单字段是否为空并给出提示。
168

被折叠的 条评论
为什么被折叠?



