周反复值出现在自动完成的jQuery [英] Repeative values occur in Autocomplete jquery

查看:176
本文介绍了周反复值出现在自动完成的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET Project.My任务的工作是prevent在Textbox.Textbox发生的repative值的绑定自动完成,并从附加文字的CheckBoxList像在下面的图片
https://drive.google.com/file/d/0B5OPwgmPG6QpTHBTdVlFaldRaEE/view ?USP =共享
之后,我从复选框列表附加内容以文本框意味着它是重复的值,如果我键入它inital一次won't.And我的任务是显示了基于文本框内容的独特价值。
我的项目文件在以下link..please帮助我的家伙

https://drive.google.com/file/d/ 0B5OPwgmPG6QpS3NMNElGN2k4RzQ /看法?USP =共享


解决方案

根据我的答案我给你在其他线程( HTTP ://stackoverflow.com/a/28828842/4569271 )我伸出我的解决方案,只显示唯一值:

\r
\r

$(函数(){\r
  $(输入[类型=复选框]')。改变(函数(){\r
    //复位输出:\r
    $(#输出)HTML('')。\r
\r
    此数组中// remeber所有唯一值:\r
    VAR tmpArray =新的Array();\r
\r
    //重复所有选中的复选框:\r
    VAR复选框= $('输入[类型=复选框]:勾选)。每个(函数(){\r
\r
      //从复选框获取价值:\r
      VAR textToAppend = $(本).VAL();\r
\r
      //检查是否已经加入由复选框值:\r
      如果(jQuery.inArray(textToAppend,tmpArray)== -1){\r
\r
        //将进入阵列,因此将不会再补充说:\r
        tmpArray.push(textToAppend);\r
\r
        。VAR existingText = $(#输出)HTML();\r
\r
        //追加分隔符(';'),如果neccessary:\r
        如果(existingText!=''){\r
          existingText = existingText +;;\r
        }\r
\r
        //打印出附加价值:\r
        $(#输出)HTML(existingText + textToAppend)。\r
      }\r
    });\r
  });\r
});

\r

&LT;脚本SRC =htt​​ps://ajax.googleapis.com/ajax /libs/jquery/2.1.1/jquery.min.js\"></script>\r
\r
&LT; H2&GT;选择:其中; / H&GT;\r
&LT;输入类型=复选框VALUE =一月/&GT;扬\r
&LT;输入类型=复选框VALUE =一月/&GT;扬\r
&LT;输入类型=复选框VALUE =一月/&GT;扬\r
&LT;输入类型=复选框VALUE =二月/&GT;二月\r
&LT;输入类型=复选框VALUE =二月/&GT;二月\r
&LT;输入类型=复选框VALUE =二月/&GT;二月\r
&LT;输入类型=复选框VALUE =三月/&GT;三月\r
&LT;输入类型=复选框VALUE =三月/&GT;三月\r
&LT;输入类型=复选框VALUE =三月/&GT;三月\r
\r
&所述; H2&GT;输出:或其可/ H2&GT;\r
&LT; D​​IV ID =输出&GT;&LT; / DIV&GT;

\r

\r
\r

根据您的描述

,我不知道这是不是你要找的解决方案?但也许它帮助。

I am working in ASP.NET Project.My task is to Prevent the repative values occured in Textbox.Textbox is bound with autocomplete and appending text from checkboxlist as like in the below picture ! https://drive.google.com/file/d/0B5OPwgmPG6QpTHBTdVlFaldRaEE/view?usp=sharing After i appended the content from checkbox list to textbox means it is repeating value,if i typed it inital time it won't.And my task is to show unique values based on the textbox content. My project files are in the below link..please help me out guys

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

解决方案

Based on my answer I gave you in the other thread (http://stackoverflow.com/a/28828842/4569271) I extended my solution to only display unique values:

$(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>

Based on your description, I am not sure if this is the solution you were looking for? But maybe it helps.

这篇关于周反复值出现在自动完成的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆