0
У меня очень длинная таблица, в которой я использую окно поиска для поиска строки таблицы. Наборы функций фокусируются на элементе строки таблицы, но сразу же переходят в окно поиска и устанавливают фокус на него. Я не знаю, почему это происходит.Фокус потерян на элемент строки таблицы сразу после его набора
<ice:inputText value="#{bean.searchStr}" maxlength="8" size="8"
onkeyup="enterToSearch(event, this.id);"/>
.....
<ice:commandLink actionListener="#{bean.search}"></ice:commandLink>
function focusSelectedRow(rowId) {
// Using some other element's id to get to the tr element
// and rowId does not correspond to the actual table row
var rowElem = document.getElementById(rowId);
var trElem = rowElem.parentNode.parentNode.parentNode;
var tableElem = trElem.parentNode.parentNode;
var children = trElem.parentNode.childNodes;
var rowNum = 1;
var rowHeight = trElem.offsetHeight;
for (var i=0 ; i < children.length ; i++) {
if(children[i] == trElem) rowNum = i+1;
}
trElem.tabIndex = 999;
trElem.style.backgroundColor = '#FFFF00';
trElem.focus();
// The below is used because, if the scroll bar is manually adjusted the focus
// is not retained for the next search
tableElem.scrollTop = rowNum*rowHeight;
}
function enterToSearch(event, id) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if(keyCode == 13)
{
document.getElementById(id).parentNode.parentNode.childNodes[3].childNodes[0].click();
}
}
У вас есть триггер в поле поиска? Каков контекст для этой функции? Нам нужно знать больше деталей, возможно, вы могли бы использовать JsFiddle. – fcortes
Пожалуйста, смотрите больше кода, можно ли выпустить JsFiddle? –