【问题标题】:Dynamicaly add/remove in jquery multiselect在jQuery多选中动态添加/删除
【发布时间】:2014-03-01 09:31:07
【问题描述】:

我第一次尝试 jquery 多选。我已将下拉列表设为多选。

我的下拉菜单是这样的,

<select id="selectChartType" multiple="multiple"  style="width:20px">
    <option value="chart1">chart1</option>
    <option value="chart2">chart2</option>
    <option value="chart3">chart3</option>
    <option value="chart4">chart4</option>
    <option value="chart5">chart5</option>
    <option value="chart6">chart6 </option>
</select>

我有像这样的多选下拉菜单

$("#selectChartType").multiselect();

它工作正常。现在我想让这个下拉列表动态化。通过单击一个按钮,上面相同的下拉菜单应该像这样改变,

<select id="selectChartType" multiple="multiple" style="width:20px">
<option value="chart3">chart3</option>
<option value="chart4">chart4</option>
</select>

我的意思是剩余的选项应该消失。当我再单击一个按钮时,它应该再次显示原始下拉列表。我只想要这里的多选逻辑。请帮我。

【问题讨论】:

  • 您是否有机会详细说明所需的行为?例如,当您说“通过单击一个按钮”时,该按钮是在其他位置但在同一页面上,还是您的意思是“单击一个选择选项”?
  • 就像我还有一个下拉菜单,我有 2 个选项,即 type1 和 type2。当我选择类型二时,下拉菜单应该像上面一样改变

标签: jquery jquery-multiselect


【解决方案1】:

我考虑你的解释,

试试这个,

例如Demo

HTML

<select id="selectChartType" multiple="multiple"  style="width:100px">
    <option value="chart1">chart1</option>
    <option value="chart2">chart2</option>
    <option value="chart3">chart3</option>
    <option value="chart4">chart4</option>
    <option value="chart5">chart5</option>
    <option value="chart6">chart6 </option>
</select>
<button class="button1" >change list</button>
<button class="button2" >change prev list</button>

Jquery:

$('.button1').click(function(){
$("#selectChartType").html('<option value="chart3">chart3</option><option value="chart4">chart4</option>')
})

$('.button2').click(function(){
$("#selectChartType").html('<option value="chart1">chart1</option><option value="chart2">chart2</option><option value="chart3">chart3</option><option value="chart4">chart4</option><option value="chart5">chart5</option><option value="chart6">chart6 </option>')
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 2013-04-25
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多