我有下一个问题:我正在使用bootstrap和knockout,我有一个自定义的打字头方法:
ko.bindingHandlers.typeahead = {
update : function(element, valueAccessor, allBindingsAccessor) {
$(element).typeahead({
source : typeaheadSource[$(element).attr('id')]
});
var span = $(element.parentElement).children("span");
if (span.length > 0) {
span[0].onclick = function() {
var t = typeaheadByElementId[$(element).attr('id')];
if (t.shown == false) {
hideAllTypeaheads();
t.showAll();
} else {
t.hide();
}
};
}
}
};
typeheadSource数组的一部分
var typeaheadSource = [];
...
typeaheadSource['buildingWalls'] = [ 'blah', 'ablah', 'cblah-blah'];
...
输入输入的html代码:
<div class='control-group'><label class='control-label' for='buildingWalls'>Материал наружных стен</label>
<div class='input-append'>
<input type='text' class='input-xlarge' id='buildingWalls' data-bind='value:buildingWalls, typeahead: true'> <span class="add-on"><i class="icon-chevron-down"></i></span>
</div>
</div>
它在firefox 18和chrome上都能正常工作,但它在Firefox 5上不起作用(例如)。关于我想要的内容:点击跨度
后,应向您显示所有提示答案 0 :(得分:0)
- var span = $(element.parentElement).children("span");
- if (span.length > 0) {
- span[0].onclick = function() {
+ var span = element.nextElementSibling;
+ if (span) {
+ span.onclick = function() {
$(element.parentElement).children(“span”)在Firefox 5中返回空数组,所以我用新的替换了这3行。