zoukankan      html  css  js  c++  java
  • js下拉框去掉重复的

                    想用jquery代码实现这样的一个功能:有一个下拉框,当选择下拉框的时候,判断选择的值有没有被选择过,如果有则提示;代码如下:

              

    $(function(){
        var authTypes=new Array();
        authTypes = $("#authTypes").val().split(',');
        $("#authType").on("change",function(){
            console.log(authTypes)
            console.log("当前选择的" + $('#authType option:selected').val())
            for(var val in authTypes){
                console.log(val)
                if($('#authType option:selected').val() == authTypes[val]){
                    console.log(val+" selected:" + $('#authType option:selected').val())
                    alert("该分类已添加过");
                    return false;
                }
            }
           /* if(checkArray.indexOf($('#authType option:selected').val())  <= -1){
                alert("该分类已添加过");
                return false;
            }*/
        })
    
     
    })
    

      大致思路是:在页面放置一个隐藏域,存放已经选择的id,逗号分隔;之后把该值赋值给一个数组;之后对数组循环,如果有则提示;没有则可以选择。

  • 相关阅读:
    知识体系总结
    计算机基础总结
    Redis总结
    Mysql总结
    JAVA基础总结
    有锁编程
    CAS
    读写自旋锁
    org.apache.log4j.Logger详解
    web.xml 中的listener、 filter、servlet 加载顺序及其详解
  • 原文地址:https://www.cnblogs.com/thinkingandworkinghard/p/7513457.html
Copyright © 2011-2022 走看看