jQuery自动完成多个字段使用id,但不使用类;如果可能的话,使用序列化
jQuery autocomplete for multiple fields using id, but not using class; using serialize if possible
HTML输入字段
<input type="text" name="partner_name_or_description[]" id="partner_name_or_description1" class="row_changed1"/>
<input type="text" name="partner_name_or_description[]" id="partner_name_or_description2" class="row_changed2"/>
<input type="text" name="partner_name_or_description[]" id="partner_name_or_description3" class="row_changed3"/>
部分jquery自动完成代码(可以工作)
$("#partner_name_or_description1:input, #partner_name_or_description2:input, #partner_name_or_description3:input").autocomplete(
"__autocomplete_source.php",
在jquery有:partner_name_or_description1, 2, 3等....我想在serialize(或其他可能的方式)中使用一些简短的内容来代替这个包含1、2、3等的长列表。
首先得到这些1,2,3…使用下面的代码
$('[id^="partner_name_or_description"]').each(function (index, partner_name_or_description) {
var s_id = partner_name_or_description.id.substring(27);
});
那就不要再写那么长的列表了
$("#partner_name_or_description" + s_id + " :input").serialize().autocomplete(
它不工作。如果查看源代码,请参见
$("#partner_name_or_description" + s_id + " :input").serialize().autocomplete(
不明白原因…可能不正确使用serialize().autocomplete
或者可以不使用serialize()
,而必须使用其他东西。
我不能使用class="row_changedX"
,因为它是必要的其他目的(类必须像row_changed1,2,3;对于每一行,类名必须不同)。
/*Actually do not understand why this is necessary, but if I delete all uncommented, then code does not work*/
function findValue(li) {
/*if( li == null ) return alert("No match!");
// if coming from an AJAX call, let's use the CityId as the value
if( !!li.extra ) var sValue = li.extra[0];
// otherwise, let's just display the value in the text box
else var sValue = li.selectValue;
alert("The value you selected was: " + sValue);*/
}
function selectItem(li) {
findValue(li);
}
function formatItem(row) {
return row[0] + " (id: " + row[1] + ")";
}
$('[id^="partner_name_or_description"]').autocomplete("__autocomplete_source.php",
{
delay:10,
minChars:2,
matchSubset:1,
matchContains:1,
cacheLength:10,
onItemSelect:selectItem,
onFindValue:findValue,
formatItem:formatItem,
autoFill:true
}//{ delay:10,
)//.autocomplete(;
编辑:感谢@jk -这将工作:
$('[id^="partner_name_or_description"]').autocomplete(
"__autocomplete_source.php",
//do stuff
});
相关文章:
- Ajax发布表单序列化,发布引号'
- 序列化数据属性中对象的最可靠方法
- YUI3 IO实用程序是否可以根据给定的内容类型标头值自动序列化数据
- 为什么JSON.stringify没有序列化原型值
- 有没有一个Nodejs库可以序列化和反序列化命名组件的路径(比如URL路径名)
- 是否可以在javascript中反序列化java对象
- jQuery Ajax数组序列化错误
- 对象序列化,JAVA,Javascript
- 在jquery中以序列化的形式传递额外的paparameter
- 如何使用angularjs序列化对象
- 使用System从C#集合创建JSON数组.网状物剧本序列化
- javascript中是否有更标准化的方法来转换(序列化)非表单数据以与ajax一起使用
- 在html标记中序列化javascript代码
- 如何在C#中反序列化json对象
- jQueryAJAX-将额外的键/值对推送到序列化的$_POST数组中
- 使用JSON序列化图论树的解决方法
- jQuery自动完成多个字段使用id,但不使用类;如果可能的话,使用序列化
- Jquery / Ajax -如果所有表单都有相同的类,如何确定要序列化哪个表单
- 如何序列化复选框,单选和多个选择元素,如果他们是空白使用Jquery SerializeArray()
- 序列化单选按钮|如果未选择单选按钮,则不提交