---
title: "jquery使用小记"
author: "yinter"
date: "2011-12-08T11:23:22Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2012-02-29T09:28:56Z"
id: 1297493
url: "https://yinter.iteye.com/blog/1297493"
---

现在开发难免会要用到jquery,但有不是很熟，把用到的记录下吧：

 

```
                var roleSelected=[];
                /*
                $.each(roleSelected, function(key, val) {
                        console.log('index in arr:' + key + ", corresponding value:" + val);
                });*/


                //选择id为taskRelateUser下的select元素中被selected值
                $("#taskRelateUser").find("select").children(":selected").each(function(i,a){
                    roleSelected.push(a.value);
                });
               
                if (hasSameElementInArray(roleSelected)){
                    alert("数据中存在相同的元素！");
                    return false;
                }

               //数组中是否有相同元素
            function hasSameElementInArray(arr){
                var hash = {};
                for(var i in arr) {
                　　if(hash[arr[i]]){
                    　　return true;
                    }
                　　hash[arr[i]] = true;
                    console.log(hash);
            　　}
            　　return false;
            }
```