2014-10-30 78 views
0

我有一个selectItem,其中包含标签,值和说明。如何在Javascript中获取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); 
    } 

我已经尝试过了如上,但我得到“未定义”,如果我把文本,而不是descrption我得到的标签值。但我想显示说明。 请帮我对这个

回答

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想要什么元件。 Sry为我的英语。

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