【问题标题】:How to get SelectItem description in Javascript如何在 Javascript 中获取 SelectItem 描述
【发布时间】:2014-10-30 05:28:54
【问题描述】:

我有一个包含标签、值和描述的 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);
  }

我已经按照上面的方法进行了尝试,但是我得到了“未定义”,如果我放置文本而不是描述,我会得到标签值。但我想显示描述。 请帮我解决这个问题

【问题讨论】:

    标签: javascript jsf


    【解决方案1】:

    检查生成的 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多