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,逗号分隔;之后把该值赋值给一个数组;之后对数组循环,如果有则提示;没有则可以选择。

  • 相关阅读:
    git ssh keys
    git 修改 email
    git 撤销commit
    企微调试模式
    ORACLE 根据某个字段固定值进行分区
    Apache FtpClient login失败
    Oracle序列
    Oracle merage into
    Oracle all_tables 以及常用sql
    性能优化-使用高性能的库fastutil
  • 原文地址:https://www.cnblogs.com/thinkingandworkinghard/p/7513457.html
Copyright © 2011-2022 走看看