ここで私はリストボックスに取り組んでおり、このリストボックスのすべての要素を繰り返しています。ここで、'list2' はリストボックスの ID であり、'list2' から取得した要素です。
$(function(){
$("#button1").click(function(){
$("#list1 > option:selected").each(function(){
$(this).remove().appendTo("#list2");
});
});
$("#button2").click(function(){
$("#list2 > option:selected").each(function(){
$(this).remove().appendTo("#list1");
});
});
});
ここでは、「list2」のすべての要素を表示するボタン 3 を作成しました。これをクリックすると、div 'placeholder; を使用して表示されます。
$("#button3").click(function(){
var count = $("#list2 option").length;
$("#list2 > option").each(function() {
document.getElementById("error").style.display='none';
document.getElementById("placeholder").style.display='block';
document.getElementById("placeholder").innerHTML= document.getElementById("placeholder").innerHTML+'<p>'+this.text+'</p>';
});
ここで「button3」をクリックすると、期待される結果が得られますが、もう一度ボタン3をクリックすると、同じ結果が別の場所に表示されます。このボタンをクリックする回数は、表示/結果の数を表示しますが、異なる場所に表示されます。
この結果が欲しいのは一度だけです。
質問:これを達成する方法はありますか? 誰かが button3 をクリックし、要素が同じである場合、それ以上は印刷されませんが、誰かが list2 の要素を変更すると、変更された結果が表示されます。
ありがとう