输入可点击的建议

时间:2014-11-01 13:47:58

标签: javascript jquery twitter-typeahead

我想通过点击建议内的按钮来防止陷入困境菜单。

代码:

$(document).ready(function(){
    $('#search2').typeahead({
            hint: true,
            highlight: true
        },
        {
            name: 'products',
            displayKey: 'name',
            source: function (query, process) {
                return $.post("php/Products.php", { action:'sell-search',search_value: query}, function (data) {
                    process(JSON.parse(data));
                });
            },
            templates: {
                empty: [
                    '<div class="empty-message text-danger">',
                    '<h3>Няма намерена стока</h3>',
                    '</div>'
                ].join('\n'),
                suggestion: Handlebars.compile(
                    '<div class="row">' +
                        '<div class="col-xs-8"><div>{{name}}</div><div class="small text-success">{{category}}</div></div>' +
                        '<div class="col-xs-3">{{price_retail}} <span class="x-small">лв/{{measure}}<span></div>'+
                        '<div class="col-xs-1"><button class="btn btn-sm btn-warning float-right products-info "><span class="glyphicon glyphicon-info-sign"></span></button></div>' +
                    '</div>')
            }
        });
});

$(document).on('click','.products-info', function(e){
    e.stopPropagation();
    console.log("Cliicked");
    console.log('Inside link');
    alert('test');
    return false;
});

我试过了

  

e.stopPropagation();

但它不起作用,并且在隐藏菜单后会发出“测试”消息。

0 个答案:

没有答案