【问题标题】:i am trying to make it so when you click one of the drop down selections, it will add to a list, here is the code of one of our drop down buttons我正在尝试这样做,因此当您单击其中一个下拉选项时,它将添加到列表中,这是我们的下拉按钮之一的代码
【发布时间】:2016-03-25 14:25:08
【问题描述】:

我们正在尝试编写一种方法来单击其中一个蔬菜选择并将其添加到页面侧面的列表中

  <div class="container">
  <h2>
  </h2>
  <p></p> 

  <div class="dropdown">
  <div  id="dropdown" style="position:fixed; left:400px; top:120px;"  class="main">
<button class="btn btn-default dropdown-toggle" type="button" id="menu1" data-toggle="dropdown">Vegetable
<span class="caret"></span></button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
  <li role="presentation"><a role="menutype" tabindex="1" href="#">Carrots</a></li>
  <li role="presentation"><a role="menuitem" tabindex="2" href="#">Tomatos</a></li>
  <li role="presentation"><a role="menuitem" tabindex="3" href="#">Lettuce</a></li>
  <li role="presentation"><a role="menuitem" tabindex="4" href="#">Peas</a></li>
  <li role="presentation"><a role="menuitem" tabindex="5" href="#">Green Beans</a></li>
  <li role="presentation"><a role="menuitem" tabindex="6" href="#">Potatoes</a></li>
  <li role="presentation"><a role="menuitem" tabindex="7" href="#">Corn</a></li>
  <li role="presentation" class="divider"></li>
</ul>

 </div>
</div>

【问题讨论】:

  • 你试过什么javascript?

标签: javascript list button


【解决方案1】:

我会创建一个新函数并将其添加到下拉列表中:

onChange="OnSelectedIndexChange()"

并根据您的需要修改此功能。在下拉列表中进行新选择后,它会将 li 项附加到您的其他列表 (ul)。也许您需要更改要获取文本而不是值的属性。

//function for changed selection
function OnSelectedIndexChange()
{
document.getElementById('myListOfItems').append("<li>"+document.getElementById('dropdown').value+"</li>");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-18
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 2016-08-31
    • 2022-11-18
    相关资源
    最近更新 更多