Domanda

Sto usando jquery scelti per creare una casella di selezione multipla. Il mio problema è che la terza opzione deve aprire una nuova finestra e non deve selezionare. (Successivamente l'utente può creare una nuova opzione in questa finestra)

Qualcuno può aiutarmi a capire questo? La mia idea è usare $('.chosen-select').on('change'...) per questo e rimuovere l'elemento selezionato dall'elenco. Ma non so come

<div class="wrapper">
  <select data-placeholder="options" style="width:350px;" multiple class="chosen-select">
     <option value=""></option>
     <option value="1">1</option>
     <option value="2">2</option>
     <option value="3" onClick="openPopup()">3</option>
 </select>
</div>
.

Grazie!

È stato utile?

Soluzione 3

L'ho risolto:

 $('.chosen-select').chosen().change( function() {
      var selectedValue = $(this).find('option:selected').val();
      if(selectedValue=='3'){
        $(this).find('option:selected').prop("selected",false);
        openPopup();
      }
      $('.chosen-select').trigger("chosen:updated");
    });
.

Altri suggerimenti

Se l'ho capito bene, questo dovrebbe risolvere il tuo problema:

$('.chosen-select').on('mouseup', function(){ // on finish the click on any part of the multiselect
   if($(this).val().indexOf('3') !== -1){ // if value has the 3 selected [1,3]
      openPopup(); // open the popup
   }
});
.

Ma se vuoi che funzioni solo sull'opzione 3 puoi fare questo

$('.chosen-select').on('mouseup','.openPopup', function(){ // on finish the click on option of class openPopup
   if($(this).val() == 3){
      openPopup(); // open the popup
   }
});
.

Per quanto riguarda la rimozione:

$('.chosen-select').on('mouseup','.openPopup', function(){ // on finish the click on option of class openPopup
   if($(this).val() == 3){
      openPopup($(this)); // open the popup
   }
});

function openPopup(obj){
    //Popup functions...
    obj.remove();
}
.

Questo dovrebbe risolvere il tuo problema

Potresti provare qualcosa del genere:

$('option[value="3"]').click(function(e){

    // The line below is just for demonstration purposes
    // you could replace with your openPopup() function

    window.open('http://www.google.com','_blank');

    // Remove the element
    $(this).remove();

    e.preventDefault(); 
});
.

Ecco un violino che mostra il comportamento in azione: http://jsfiddle.net/95xs5/2/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top