2015-03-03 78 views
0

我在ASP.NET項目中工作。我的任務是防止在Textbox.Textbox出現的補救值綁定與自動完成和附加複選框列表中的文本,就像下面的圖片 ! https://drive.google.com/file/d/0B5OPwgmPG6QpTHBTdVlFaldRaEE/view?usp=sharing 當我把複選框列表中的內容附加到文本框意味着它重複的價值,如果我輸入它在最初的時間它不會。我的任務是顯示基於文本框內容的唯一值。 我的項目文件都在下面link..please幫我出球員重複值出現在自動完成jquery

https://drive.google.com/file/d/0B5OPwgmPG6QpS3NMNElGN2k4RzQ/view?usp=sharing

回答

1

根據我的答案,我給你在其他線程(https://stackoverflow.com/a/28828842/4569271)我伸出我的解決方案,只顯示唯一值:

$(function() { 
 
    $('input[type="checkbox"]').change(function() { 
 
    // Reset output: 
 
    $("#output").html(''); 
 

 
    // remeber all unique values in this array: 
 
    var tmpArray = new Array(); 
 

 
    // Repeat for all checked checkboxes: 
 
    var checkboxes = $('input[type="checkbox"]:checked').each(function() { 
 

 
     // Get value from checkbox: 
 
     var textToAppend = $(this).val(); 
 

 
     // Check if value from checkbox was added already: 
 
     if (jQuery.inArray(textToAppend, tmpArray) == -1) { 
 

 
     // add entry to array so it will be not added again: 
 
     tmpArray.push(textToAppend); 
 

 
     var existingText = $("#output").html(); 
 

 
     // Append seperator (';') if neccessary: 
 
     if (existingText != '') { 
 
      existingText = existingText + ";"; 
 
     } 
 

 
     // Print out append value: 
 
     $("#output").html(existingText + textToAppend); 
 
     } 
 
    }); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<h2>Select:</h2> 
 
<input type="checkbox" value="Jan" />Jan 
 
<input type="checkbox" value="Jan" />Jan 
 
<input type="checkbox" value="Jan" />Jan 
 
<input type="checkbox" value="Feb" />Feb 
 
<input type="checkbox" value="Feb" />Feb 
 
<input type="checkbox" value="Feb" />Feb 
 
<input type="checkbox" value="Mar" />Mar 
 
<input type="checkbox" value="Mar" />Mar 
 
<input type="checkbox" value="Mar" />Mar 
 

 
<h2>Output:</h2> 
 
<div id="output"></div>

根據您的描述,我不知道如果這是你要找的解決方案嗎?但也許它有幫助。