1

我想要一个执行以下操作的选择列表:

  1. When the select list is open, display the list of descriptions.
  2. 当用户选择一个项目时,选择列表将关闭,仅显示该值。

这样做的原因是为了节省空间,因为值会更短。我希望在 jQuery 中有一个答案。

谢谢。

4

1 回答 1

0

好的,我已经解决了:

$("#selectList").focus(function() {
  var selectedOption = $(this).find("option:selected");
  selectedOption.text(selectedOption.attr("description"));
});

$("#selectList").change(function() {
  var selectedOption = $(this).find("option:selected");
  selectedOption.attr("description", selectedOption.text());
  selectedOption.text(selectedOption.val());
});

var currSelOption = $("#selectList").find("option:selected");
currSelOption.attr("description", currSelOption .text());
currSelOption.text(currSelOption .val());

它可能会被优化一点。

于 2010-05-12T21:45:53.137 回答