0

タグ付けのselect2 例でvalueは、開発者は対応する要素の を動的に生成しましたinput(#e12)。ユーザーがオプションを選択または選択解除するたびvalueに、入力の が即座に変更されます。

//JS for example
$("#e12").select2({tags:["red", "green", "blue"]});

//Corresponding html
<input type="hidden" id="e12" value="brown,red,green" tabindex="-1" class="select2-offscreen">

//Corresponding html if the user unselects "brown"
<input type="hidden" id="e12" value="red,green" tabindex="-1" class="select2-offscreen">

textarea要素に対して同じことをしたい。ただし、例に示すようにタグを追加すると、value動的textareaに変更されます。

完全な JS はこのパスティにあります: http://pastie.org/private/0uhoyqiqauhcx40av5j68g

//My JS, truncated.  
$(".addPeopleToCohort").select2({
        tags: ["David Baldwin", "Gonzo Loopy", "Eric Baldwin", "Terry Stark"],
        ...
//Corresponding HTML, note the lack of a value field
<textarea class="addPeopleToCohort select2-offscreen" name="students" tabindex="-1">

textarea動的に更新されるvalueフィールドを取得するにはどうすればよいですか?

4

1 に答える 1