【问题标题】:Taking Selected Item of ListBox into selected TextBox将 ListBox 的选定项放入选定的 TextBox
【发布时间】:2013-03-22 16:02:26
【问题描述】:

我有一个 ListBox 对象,它允许多项选择,也允许删除选定的项目。

现在我有一个额外的问题,它与一个列表框和 3 个文本框有关。 我希望它能够工作,以便当我将焦点转移到任何文本框或将鼠标悬停在任何文本框上时,我希望将 ListBox 所选项目复制到接收焦点/鼠标悬停的文本框中。

我该怎么做? 请帮帮我。

【问题讨论】:

  • 你应该更加努力tinyurl.com/so-hints(尤其是“示例代码和数据”“拼写、语法和格式”
  • @TimSchmelter 你没有避免禁止你尝试过 cmets 吗?
  • @SamIam:从什么时候开始“你尝试了什么”是个坏问题? meta.stackexchange.com/a/131031/147438
  • @TimSchmelter 从昨天开始。 meta.stackexchange.com/questions/172758/…
  • @SamIam:我想你把我和 Soner 搞混了,因为他想看代码。但是,恕我直言,告诉(新)用户他们应该展示他们尝试过的东西也不错。这澄清了问题并表明有人在提出问题之前已经尝试过任何事情。

标签: c# asp.net


【解决方案1】:

这是您可以从列表框中获取一个选项项的方法, 要获得多个选项,您必须遍历列表框中的选项项集合。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <head runat="server">
    <title></title>
    <script type="text/javascript">
      function GrabFromListbox() {
      window.document.getElementById("TextArea1").value += window.document.getElementById("lstFruits").options[window.document.getElementById("lstFruits").selectedIndex].text + "\n";
      }
    </script>
  </head>

  <body>
    <form id="form1" runat="server">
      <div>
        <select id="lstFruits" name="lstFruits" multiple="multiple" size="8">
          <option value="0" selected="selected">Please select</option>
          <option value="1">Apples</option>
          <option value="2">Pears</option>
          <option value="3">Bananas</option>
          <option value="4">Oranges</option>
        </select><br /><br />
        <input type="text" id="TextArea1" name="TextArea1" value="" onmouseover="GrabFromListbox()" />
      </div>
    </form>
  </body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    相关资源
    最近更新 更多