用于搜索和多选的下拉列表中的TextBox [英] TextBox With In Dropdownlist For Searching and Multiple Select

查看:74
本文介绍了用于搜索和多选的下拉列表中的TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个文本框,用于搜索下拉列表中的项目和复选框列表,以便在下拉列表中进行多项选择





我的代码在这里,但是不执行完整的任务





i want to add a textbox for searching items in dropdownlist and checkboxlist for multiple selection inside dropdownlist


my code here but did not perform complete task


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Combobox</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <style>
  .custom-combobox {
    position: relative;
    display: inline-block;
  }
  .custom-combobox-toggle {
    position: absolute;
    top: 0;
    bottom: 0;
    margin-left: -1px;
    padding: 0;
    /* support: IE7 */
    *height: 1.7em;
    *top: 0.1em;
  }
  .custom-combobox-input {
    margin: 0;
    padding: 0.3em;
  }
  </style>
  <script>
  (function( $ ) {
    $.widget( "custom.combobox", {
      _create: function() {
        this.wrapper = $( "<span>" )
          .addClass( "custom-combobox" )
          .insertAfter( this.element );

        this.element.hide();
        this._createAutocomplete();
        this._createShowAllButton();
      },

      _createAutocomplete: function() {
        var selected = this.element.children( ":selected" ),
          value = selected.val() ? selected.text() : "";

        this.input = $( "<input>" )
          .appendTo( this.wrapper )
          .val( value )
          .attr( "title", "" )
          .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
          .autocomplete({
            delay: 0,
            minLength: 0,
            source: $.proxy( this, "_source" )
          })
          .tooltip({
            tooltipClass: "ui-state-highlight"
          });

        this._on( this.input, {
          autocompleteselect: function( event, ui ) {
            ui.item.option.selected = true;
            this._trigger( "select", event, {
              item: ui.item.option
            });
          },

          autocompletechange: "_removeIfInvalid"
        });
      },

      _createShowAllButton: function() {
        var input = this.input,
          wasOpen = false;

        $( "<a>" )
          .attr( "tabIndex", -1 )
          .attr( "title", "Show All Items" )
          .tooltip()
          .appendTo( this.wrapper )
          .button({
            icons: {
              primary: "ui-icon-triangle-1-s"
            },
            text: false
          })
          .removeClass( "ui-corner-all" )
          .addClass( "custom-combobox-toggle ui-corner-right" )
          .mousedown(function() {
            wasOpen = input.autocomplete( "widget" ).is( ":visible" );
          })
          .click(function() {
            input.focus();

            // Close if already visible
            if ( wasOpen ) {
              return;
            }

            // Pass empty string as value to search for, displaying all results
            input.autocomplete( "search", "" );
          });
      },

      _source: function( request, response ) {
        var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
        response( this.element.children( "option" ).map(function() {
          var text = $( this ).text();
          if ( this.value && ( !request.term || matcher.test(text) ) )
            return {
              label: text,
              value: text,
              option: this
            };
        }) );
      },

      _removeIfInvalid: function( event, ui ) {

        // Selected an item, nothing to do
        if ( ui.item ) {
          return;
        }

        // Search for a match (case-insensitive)
        var value = this.input.val(),
          valueLowerCase = value.toLowerCase(),
          valid = false;
        this.element.children( "option" ).each(function() {
          if ( $( this ).text().toLowerCase() === valueLowerCase ) {
            this.selected = valid = true;
            return false;
          }
        });

        // Found a match, nothing to do
        if ( valid ) {
          return;
        }

        // Remove invalid value
        this.input
          .val( "" )
          .attr( "title", value + " didn't match any item" )
          .tooltip( "open" );
        this.element.val( "" );
        this._delay(function() {
          this.input.tooltip( "close" ).attr( "title", "" );
        }, 2500 );
        this.input.data( "ui-autocomplete" ).term = "";
      },

      _destroy: function() {
        this.wrapper.remove();
        this.element.show();
      }
    });
  })( jQuery );

  $(function() {
    $( "#combobox" ).combobox();
    $( "#toggle" ).click(function() {
      $( "#combobox" ).toggle();
    });
  });
  </script>
</head>
<body>
 <form id="form1" runat="server">
<div class="ui-widget">
  <label>Your preferred programming language: </label>
  <asp:DropDownList ID="combobox" runat="server" AutoPostBack="true"

        onselectedindexchanged="combobox_SelectedIndexChanged">

    <asp:ListItem Text="A" Value="A"></asp:ListItem>
        <asp:ListItem Text="ActionScript" Value="AB"></asp:ListItem>
        <asp:ListItem Text="AppleScript" Value="AC"></asp:ListItem>
        <asp:ListItem Text="AD" Value="AD"></asp:ListItem>
        <asp:ListItem Text="AE" Value="AE"></asp:ListItem>
        <asp:ListItem Text="B" Value="B"></asp:ListItem>
        <asp:ListItem Text="C" Value="C"></asp:ListItem>
        <asp:ListItem Text="D" Value="D"></asp:ListItem>
        <asp:ListItem Text="E" Value="E"></asp:ListItem>
        <asp:ListItem Text="F" Value="F"></asp:ListItem>
        <asp:ListItem Text="G" Value="G"></asp:ListItem>
        <asp:ListItem Text="H" Value="H"></asp:ListItem>
        <asp:ListItem Text="I" Value="I"></asp:ListItem>
        <asp:ListItem Text="J" Value="J"></asp:ListItem>
        <asp:ListItem Text="K" Value="K"></asp:ListItem>
        <asp:ListItem Text="L" Value="L"></asp:ListItem>
        <asp:ListItem Text="M" Value="M"></asp:ListItem>
        <asp:ListItem Text="N" Value="N"></asp:ListItem>
        <asp:ListItem Text="O" Value="O"></asp:ListItem>
        <asp:ListItem Text="P" Value="P"></asp:ListItem>
        <asp:ListItem Text="Q" Value="Q"></asp:ListItem>
        <asp:ListItem Text="R" Value="R"></asp:ListItem>
        <asp:ListItem Text="S" Value="S"></asp:ListItem>
        <asp:ListItem Text="T" Value="T"></asp:ListItem>
        <asp:ListItem Text="U" Value="U"></asp:ListItem>
        <asp:ListItem Text="V" Value="V"></asp:ListItem>
        <asp:ListItem Text="W" Value="W"></asp:ListItem>
        <asp:ListItem Text="X" Value="X"></asp:ListItem>
        <asp:ListItem Text="Y" Value="Y"></asp:ListItem>
        <asp:ListItem Text="Z" Value="Z"></asp:ListItem>

    </asp:DropDownList>
</div>
<button id="toggle">Show underlying select</button>
 <asp:Label ID="Label1" runat="server"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 </form>
</body>
</html>

推荐答案

) {


.widget( \"custom.combobox\", {
_create: function() {
this.wrapper =
.widget( "custom.combobox", { _create: function() { this.wrapper =


( \"<span>\" )
.addClass( \"custom-combobox\" )
.insertAfter( this.element );

this.element.hide();
this._createAutocomplete();
this._createShowAllButton();
},

_createAutocomplete: function() {
var selected = this.element.children( \":selected\" ),
value = selected.val() ? selected.text() : \"\";

this.input =
( "<span>" ) .addClass( "custom-combobox" ) .insertAfter( this.element ); this.element.hide(); this._createAutocomplete(); this._createShowAllButton(); }, _createAutocomplete: function() { var selected = this.element.children( ":selected" ), value = selected.val() ? selected.text() : ""; this.input =


这篇关于用于搜索和多选的下拉列表中的TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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