2016-07-29 5 views
1

Ich habe comobox implementiert, aber mein Problem ist, ich möchte zwei Combobox für mein Projekt zu implementieren, und ich möchte die verschiedenen IDs für sie wie folgt zuweisen <select id="size1". Wie kann die assign-ID zu dieser <select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6"> und wenn i-ID an die Auswahl-Tags in HTML zuweisen, wie kann ich das gleiche tun in der jQuery-Code $(".chosen-select").chosen();Wie ID zu den Auswahl Tags zuweisen

sollte ich die Jquery-Code zu ändern, wenn ich die ID wählen Tags hinzufügen?

Unten ist mein Code

$(function(){ 
 
    $(".chosen-select").chosen(); 
 
});
<link rel="stylesheet" href="http://harvesthq.github.io/chosen/chosen.css" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> 
 
    <script src="http://harvesthq.github.io/chosen/chosen.jquery.js" type="text/javascript"></script> 
 
<div> 
 
      <em>Multiple Select with Groups</em><br /> 
 
      <select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6"> 
 
      <option value="" /> 
 
      <optgroup label="NFC EAST"> 
 
       <option />Dallas Cowboys 
 
       <option />New York Giants 
 
       <option />Philadelphia Eagles 
 
       <option />Washington Redskins 
 
      </optgroup> 
 
      <optgroup label="NFC NORTH"> 
 
       <option />Chicago Bears 
 
       <option />Detroit Lions 
 
       <option />Green Bay Packers 
 
       <option />Minnesota Vikings 
 
      </optgroup> 
 
      <optgroup label="NFC SOUTH"> 
 
       <option />Atlanta Falcons 
 
       <option />Carolina Panthers 
 
       <option />New Orleans Saints 
 
       <option />Tampa Bay Buccaneers 
 
      </optgroup> 
 
      <optgroup label="NFC WEST"> 
 
       <option />Arizona Cardinals 
 
       <option />St. Louis Rams 
 
       <option />San Francisco 49ers 
 
       <option />Seattle Seahawks 
 
      </optgroup> 
 
      <optgroup label="AFC EAST"> 
 
       <option />Buffalo Bills 
 
       <option />Miami Dolphins 
 
       <option />New England Patriots 
 
       <option />New York Jets 
 
      </optgroup> 
 
      <optgroup label="AFC NORTH"> 
 
       <option />Baltimore Ravens 
 
       <option />Cincinnati Bengals 
 
       <option />Cleveland Browns 
 
       <option />Pittsburgh Steelers 
 
      </optgroup> 
 
      <optgroup label="AFC SOUTH"> 
 
       <option />Houston Texans 
 
       <option />Indianapolis Colts 
 
       <option />Jacksonville Jaguars 
 
       <option />Tennessee Titans 
 
      </optgroup> 
 
      <optgroup label="AFC WEST"> 
 
       <option />Denver Broncos 
 
       <option />Kansas City Chiefs 
 
       <option />Oakland Raiders 
 
       <option />San Diego Chargers 
 
      </optgroup> 
 
      </select> 
 
     </div>

Antwort

1

Das trivial war. Das hast du erwartet?

$(function(){ 
 
    $("#select1").chosen(); 
 
    $("#select2").chosen(); 
 
});
<link rel="stylesheet" href="http://harvesthq.github.io/chosen/chosen.css" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> 
 
    <script src="http://harvesthq.github.io/chosen/chosen.jquery.js" type="text/javascript"></script> 
 
<div> 
 
      <em>Multiple Select with Groups</em><br /> 
 
      <select id="select1" data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6"> 
 
      <option value="" /> 
 
      <optgroup label="NFC EAST"> 
 
       <option />Dallas Cowboys 
 
       <option />New York Giants 
 
       <option />Philadelphia Eagles 
 
       <option />Washington Redskins 
 
      </optgroup> 
 
      <optgroup label="NFC NORTH"> 
 
       <option />Chicago Bears 
 
       <option />Detroit Lions 
 
       <option />Green Bay Packers 
 
       <option />Minnesota Vikings 
 
      </optgroup> 
 
      <optgroup label="NFC SOUTH"> 
 
       <option />Atlanta Falcons 
 
       <option />Carolina Panthers 
 
       <option />New Orleans Saints 
 
       <option />Tampa Bay Buccaneers 
 
      </optgroup> 
 
      <optgroup label="NFC WEST"> 
 
       <option />Arizona Cardinals 
 
       <option />St. Louis Rams 
 
       <option />San Francisco 49ers 
 
       <option />Seattle Seahawks 
 
      </optgroup> 
 
      <optgroup label="AFC EAST"> 
 
       <option />Buffalo Bills 
 
       <option />Miami Dolphins 
 
       <option />New England Patriots 
 
       <option />New York Jets 
 
      </optgroup> 
 
      <optgroup label="AFC NORTH"> 
 
       <option />Baltimore Ravens 
 
       <option />Cincinnati Bengals 
 
       <option />Cleveland Browns 
 
       <option />Pittsburgh Steelers 
 
      </optgroup> 
 
      <optgroup label="AFC SOUTH"> 
 
       <option />Houston Texans 
 
       <option />Indianapolis Colts 
 
       <option />Jacksonville Jaguars 
 
       <option />Tennessee Titans 
 
      </optgroup> 
 
      <optgroup label="AFC WEST"> 
 
       <option />Denver Broncos 
 
       <option />Kansas City Chiefs 
 
       <option />Oakland Raiders 
 
       <option />San Diego Chargers 
 
      </optgroup> 
 
      </select> 
 
     </div> 
 

 
<div> 
 
      <em>Multiple Select with Groups</em><br /> 
 
      <select id="select2" data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6"> 
 
      <option value="" /> 
 
      <optgroup label="NFC EAST"> 
 
       <option />Dallas Cowboys 
 
       <option />New York Giants 
 
       <option />Philadelphia Eagles 
 
       <option />Washington Redskins 
 
      </optgroup> 
 
      <optgroup label="NFC NORTH"> 
 
       <option />Chicago Bears 
 
       <option />Detroit Lions 
 
       <option />Green Bay Packers 
 
       <option />Minnesota Vikings 
 
      </optgroup> 
 
      <optgroup label="NFC SOUTH"> 
 
       <option />Atlanta Falcons 
 
       <option />Carolina Panthers 
 
       <option />New Orleans Saints 
 
       <option />Tampa Bay Buccaneers 
 
      </optgroup> 
 
      <optgroup label="NFC WEST"> 
 
       <option />Arizona Cardinals 
 
       <option />St. Louis Rams 
 
       <option />San Francisco 49ers 
 
       <option />Seattle Seahawks 
 
      </optgroup> 
 
      <optgroup label="AFC EAST"> 
 
       <option />Buffalo Bills 
 
       <option />Miami Dolphins 
 
       <option />New England Patriots 
 
       <option />New York Jets 
 
      </optgroup> 
 
      <optgroup label="AFC NORTH"> 
 
       <option />Baltimore Ravens 
 
       <option />Cincinnati Bengals 
 
       <option />Cleveland Browns 
 
       <option />Pittsburgh Steelers 
 
      </optgroup> 
 
      <optgroup label="AFC SOUTH"> 
 
       <option />Houston Texans 
 
       <option />Indianapolis Colts 
 
       <option />Jacksonville Jaguars 
 
       <option />Tennessee Titans 
 
      </optgroup> 
 
      <optgroup label="AFC WEST"> 
 
       <option />Denver Broncos 
 
       <option />Kansas City Chiefs 
 
       <option />Oakland Raiders 
 
       <option />San Diego Chargers 
 
      </optgroup> 
 
      </select> 
 
     </div>

+0

Dank dafür, wie ich für ausgewählte Tags erwartete Verhalten tun kann ich http bedeuten: // stackoverflow.com/questions/38619548/how-to-choose-the-text-without-selection-in-jquery-chosen-plugin – overflowstack9

+0

Ich möchte so http://stackoverflow.com/questions/38619548/how-to- choose-the-text-ohne-auswahl-in-jquery-selected-plugin Wenn Sie nichts dagegen haben – overflowstack9

+1

sicher, ich werde einen Blick in t hat auch ... – kukkuz

1

Sie können id auf select-Tag gesetzt.

In HTML So:

<select id="size1" data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6"></select> 

<select id="size2" data-placeholder="Team 2" style="width:350px;" class="chosen-select" multiple tabindex="6"></select> 

In jquery Sie diese ID wie folgt aufrufen können:

$(function(){ 
    $("#size1").chosen(); 
    $("#size2").chosen(); 
});