【问题标题】:Failed to bind twitter bootstrap typeahead for JQuery Generated rows with text fields无法为带有文本字段的 JQuery 生成的行绑定 twitter bootstrap typeahead
【发布时间】:2013-05-15 10:48:00
【问题描述】:

我有一个单行表,行在其第一个单元格中有一个文本字段,并且在单独的 js 文件中绑定到 twitter bootstrap typeahead 的文本字段。但是用户可以使用添加按钮创建行,并且克隆第一行以创建其他行。现在我希望预先输入在这些克隆的文本字段中工作得很好,但它没有,并且控制台中没有显示错误。克隆的文本字段与原始文本字段具有相同的 id 和名称。知道为什么会这样吗?以及如何处理它的任何建议?

【问题讨论】:

  • 我已经找到了这个库 github.com/brandonaaron/livequery/downloads,但如果我能在我的项目中不添加另一个库的情况下解决这个问题,我将不胜感激
  • 你能分享一些代码吗?克隆的行是如何创建的?

标签: jquery twitter-bootstrap bootstrap-typeahead


【解决方案1】:

我猜想 .typeahead() 没有在动态创建/克隆的行上启动。您可以在添加行时触发事件并使用 jquery .on()... 附加预先输入...

$('#btnAddRow').click(function(){
    var newRow = $('<div class="row"><input type="text" placeholder="Start typing.." class="typeahead" data-items="3"></div>');
    newRow.insertBefore('#addRow');
    $('.typeahead').trigger('added');

});

$('.typeahead').on('added',function(){
    $('.typeahead').typeahead(typeaheadSettings);
});

Here's a working example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-18
    • 2017-06-03
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多