2016-03-01 136 views
1

当用户点击“全选”时,我需要在选择框下的单个“li”中显示所有选项。我觉得我错过了简单的事情。这是我到目前为止有:https://jsfiddle.net/m5adns2y/2/从select中选择所有选项并显示每个选项

enter code here 

正如你所看到的,当你按下按钮,每一个结果是“[对象HTMLOptionElement]”。我需要文字。

将onTeam [i]更改为onTeam.text()[i]也无济于事。

任何人有任何建议吗?

+0

你是CL用'onTeam.text()[i]'到右页,但你需要引用数组元素,然后像'onTeam [i] .text'这样的文本属性 – shamsup

回答

1

试试这个。这是非常简单和直接的jQuery解决方案。

$('#selectAllTeamMembers').click(function() { 

    $(".add-team-member option").each(function(index) 
    { 
    if(index == 0) 
    return; 
    $('.assigned-users-list').append('<li><div class="tag-list-item"><span>' + $(this).text() + '</span> <i class="fa fa-times-circle" data-idx="' + index + '"></i></div></li>'); 
    }); 

    $(this).prop("disabled",true); 
    }); 

工作例如:https://jsfiddle.net/DinoMyte/m5adns2y/7/