引用类型
来源:互联网 发布:淘宝被罩 编辑:程序博客网 时间:2024/04/19 13:08
一、问题:当需要对两个或多个“对象”进行比较时...;
二、条件:1、创建一个只能存放两个(或多个)数值的数组 ; 2、同一数值不能重复存放
三、方法:直接看代码:
.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }1: //创建一个新的数组2: var arrayList = new Array();3:
4: //用于辅助判断是否含有重复值;5: var tureOrFalse = 0;6:
7: //检测方法8: function checkArrayList(_this,_num){9: //判断数组的个数是否超过了指定的值;10: if(arrayList.length < _num){11: //获得存放数组的值(这里用ID);12: var thisId = $(_this).attr("id");13: for( var j=0 ; j<arrayList.length ; j++){14: if(thisId == arrayList[j]){15: tureOrFalse ++;
16: }
17: }
18: //获得值后进行检测已有的数组中是否含有将要加入的值;19: if(tureOrFalse > 0){20: tureOrFalse = 0;
21: alert("亲,你已选了该数值,不能重复选择的哦!");22: }else{23: arrayList[arrayList.length] = thisId;
24: }
25: }else{26: alert("亲,你已选择了"+ _num+"个数值进行对比了哦!!")27: }
28: }
29:
30:
31: //点击进行添加对比的对象;32: $(".clickSpan").click(function(){33: // 2为你所以对比的总个数;34: checkArrayList(this,"2");35:
36: });
37:
38:
39:
40: //清除数组41: $(".c").click(function(){42: arrayList = [];
43: alert("GOOD! 数组清除成功!!");44: });
45:
46: //打印数组47: $(".p").click(function(){48: if(arrayList.length > 0){49: var list = "";50: for( var p=0 ; p<arrayList.length ; p++){51: list += "第"+ (p+1) + "个为:" + arrayList[p] + "\n";52: }
53: alert(list);
54: }else{55: alert("亲,你的动作也真是太快了。该数组还没有加入值哦!!");56: }
57:
58: });
59:
60:
四、具体例子下载:点击这里
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 引用类型
- 在VC中使用自定义资源,FindResource,LoadResource,LockResource
- 【数据结构】红黑树/AVL树的分析
- 嵌入式sqlite数据库的及触发器的研究
- Oracle SQL的优化
- 系统和外设交换数据的模式
- 引用类型
- j2ee关于使用fileupload上传文件名称及内容乱码
- 【面试中的】C语言实现字符串函数
- 安装RPM 安装文件
- 二分查找
- Android数据文件的访问权限
- 比较全面的gdb调试命令
- 多屏互动解决方案
- 小小线程池