0

这是我的 HTML

<input data-provide="typeahead" type="text"  id="actor" name="actor" autofocus="autofocus" maxlength="30" value="" required="required">

我正在使用 Ajax 作为源代码:

actors = getActors();
$('#actor').typeahead({
    source: actors,
    items: 10
});

如果我保留我的输入divid,actor那么一切都会正常工作,但如果将DIVid 从更改actoractor[]thentypeahead则不起作用。

对于actor[]id 我的代码是:

<input data-provide="typeahead" type="text"  id="actor[]" name="actor" autofocus="autofocus" maxlength="30" value="" required="required" >

actors = getActors();
    $('#actor[]').typeahead({
        source: actors,
        items: 10
    });

如果有人知道这种类型输入的解决方案,ID请提供您的解决方案。

4

1 回答 1

1

大概 jQuery 的选择器引擎试图解释'#actor[]'为一个由属性的存在限定的元素并且不匹配。为什么一定要使用那种ID(一对空方括号通常用作表单元素名称的后缀,以便PHP或类似代码将多个同名元素的值转换为数组,但ID根据定义在一个页面中是唯一的)?

于 2012-08-25T06:40:52.480 回答