0

jQueryを使用して複数のリストからアイテムを削除する必要があります

HTML:

<input type="checkbox" id="theCheckbox"/>
<select id="theSelect" multiple="multiple">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

JavaScript:

$("#theCheckbox").change(function() {
    $("#theSelect").attr("multiple", (this.checked) ? "multiple" : "");
}).change();

これがその例です。

これは私のプロジェクトからの私のコードです。このコードを実装していただければ幸いです。 マイコード

4

3 に答える 3

2

削除するオプションを選択して、そのremove()関数を呼び出すだけです。

$('#theSelect option:eq(1)').remove();

http://jsfiddle.net/DdhSF/162/

于 2012-09-13T12:12:04.637 に答える
0

複数選択リストの削除は、この編集を参照してください

両方の状態が機能します。

$("#theCheckbox").change(function() {
    $("#theSelect").attr("multiple", (this.checked) ? "multiple" : "");
}).change();

$('a').click(function() {
    $('#theSelect option:selected').remove();
});
于 2012-09-13T12:21:23.990 に答える
0
$('#theSelect').change(function(){
    var selectedIndex = $(this)[0].selectedIndex;
    //alert(selectedIndex);
    var selected = $(this).children("option").eq(selectedIndex);
    selected.remove();
});
$("#theCheckbox").change(function() {
    $("#theSelect").attr("multiple", (this.checked) ? "multiple" : "");
}).change();​
于 2012-09-13T12:26:06.697 に答える