2016-03-23 9 views
0

私はselect2を使用しています。これは1つの選択肢として使用しています。私が選択した結果を別のdivに移動したい。select2の結果を他のdivに移動

私のコードを確認してください:

https://jsfiddle.net/hxe7wr65/

それを移動する方法は?その結果をボックスに表示したくないからです。私はボックスをまだ明確にしたい、そして私が選択した後でさえ、プレースホルダはまだ現れる。

これは私が今、そのイメージで

enter image description here

をやっているデザインです。 1つのオプションのみを選択できます。私たちが選んだ後。結果は別の場所に表示されるため、選択項目にはプレースホルダが残ります。みんな私を助けてください。 ありがとうございました

+0

誰かをクリアする

var $eventSelect = $("#position"); //select your select2 input $eventSelect.on('select2:select', function(e) { var text = e.params.data.text $("#otherdiv").append(text) }) 

?助けてください – vicario

答えて

0

[OK]を私は100%これはあなたが探していることを確認していないが、私はあなたが最後に選択したアイテムのグラブ値をwan'tだと思う別のd​​ivに転送し、入力。 最初の手順では、イベントハンドラを追加します。

var $eventSelect = $("#position"); //select your select2 input 

$eventSelect.on('select2:select', function(e) { 
    console.log('select') 
    console.log(e.params.data.id) //This will give you the id of the selected attribute 
    console.log(e.params.data.text) //This will give you the text of the selected text 
}) 

値があるので、他のdivに転送するのは比較的簡単です。その後、フォームに

var $eventSelect = $("#position"); //select your select2 input 

$eventSelect.on('select2:select', function(e) { 
    var text = e.params.data.text 
    $("#otherdiv").append(text) 
    $(this).val(''); 
    // or depending no what version you are using 
    $(this).select2('val', '') 
}) 
関連する問題