我想通过在 javascript 代码中设置它们来直接设置在 jsf 块中定义的列表框元素,但是 document.getElementById() 返回 null ?
JSF 代码:
<h:panelGroup id="dtEffectiveDate">
<h:outputText value="EffectiveDates:" style="margin-left: 250px;width:76px;"/>
<h:selectManyListbox id="effectiveDateListbox" style="margin-left: 15px; width:76px;" size="2">
<c:selectItems id="effectiveDateSelectItems" value="#{manualDataEntryRegText.effectiveDates}"/>
</h:selectManyListbox>
</h:panelGroup>
JavaScript 代码:
CalendarPopup.handleSelectForMultipleDates = function(type, args, obj, inputEl)
{
alert("MultiSelect");
var arrDates = CalendarPopup.effectiveDateCalendar.getSelectedDates();
var length = arrDates.length;
var i=0;
var tokenizedDates = "";
var txtDate = document.getElementById("pageForm:effectiveDateListbox");
alert(txtDate); // returns null
for (i = 0; i!= length; i++)
{
var date = arrDates[i];
var displayMonth = date.getMonth() + 1;
var displayYear = date.getFullYear();
var displayDate = date.getDate();
tokenizedDates = displayMonth.toString(10) + "/" + displayDate.toString(10) + "/" + displayYear.toString(10);
effectiveDateListbox.options[i].value = tokenizedDates;
i++;
}
}
编辑:我能够获取列表框但无法设置它:如何设置列表框?
var listBox = document.getElementById('pageForm:effectiveDateListbox');
for (i = 0; i!= length; i++)
{
var date = arrDates[i];
var displayMonth = date.getMonth() + 1;
var displayYear = date.getFullYear();
var displayDate = date.getDate();
tokenizedDates = displayMonth.toString(10) + "/" + displayDate.toString(10) + "/" + displayYear.toString(10);
listBox.options[i].value = tokenizedDates;
i++;
}