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,逗號分隔;之后把該值賦值給一個數組;之后對數組循環,如果有則提示;沒有則可以選擇。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM