如何在Javascript中获取SelectItem描述

时间:2014-10-30 05:28:55

标签: javascript jsf

我有一个包含标签,值和描述的selectItem。

  SelectItem item1 = new SelectItem();
    item1.setLabel("Code1");
    item1.setValue("Code1");
    item1.setDescription("This is the place to display actual Long discription for Code1");

我想在jsf页面中将描述值显示为悬停文本。

var oprions  = document.getElementsByTagName("option");
  for (var optIndex in oprions){
      options[optIndex].title = options[optIndex].description;
      alert("value is : " + options[optIndex].title);
  }

我已经尝试过如上所述,但是我得到了#undefined',如果我放置文字而不是描述我得到标签值。但我想显示描述。 请帮帮我

1 个答案:

答案 0 :(得分:0)

检查你的结果html。如果您尝试在p:selectOneMenu或其他用于选择的元素中使用它,您可以这样:

<p:selectOneMenu>
  <f:selectItem value="#{seedvarManagedBean.item1}" />
</p:selectOneMenu>

生成:

<div id="seedvar_form:j_idt15_panel" class="ui-selectonemenu-panel ui-widget-content ui-corner-all ui-helper-hidden ui-shadow" style="width: 225px; z-index: 1003; display: block; top: 409.078125px; left: 412.59375px;">
  <div class="ui-selectonemenu-items-wrapper" style="height:auto">
    <ul class="ui-selectonemenu-items ui-selectonemenu-list ui-widget-content ui-widget ui-corner-all ui-helper-reset">
      <li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all ui-state-highlight" data-label="Code1" title="This is the place to display actual Long discription for Code1">Code1</li>
    </ul>
  </div>
</div>

您可以从li元素中获得所需内容。为我的英语而烦恼。

如果您有纯HTML选择元素,请检查您的拼写错误。您已定义变量oprions,但在循环中尝试使用options