jQuery 插件autocomplete 应用

介绍

 $("#AccountNames").autocomplete(Accounts, {
minChars: 0,
matchContains: true,
mustMatch: false,
multiple: true,
multipleSeparator: ',',
formatItem: function (row, i, max) {
if ($("input[name='AccountIds'][value=" + row.AccountId + "]").size() == 0) {
if (row.FullName!=row.AccountName)
return row.AccountName + "(" + row.FullName + ")";
else
return row.AccountName;
} else {
return false;
}
},
formatMatch: function (row, i, max) {
if (row.FullName!=row.AccountName)
return row.AccountName + "(" + row.FullName+")";
else
return row.AccountName;
},
formatResult: function (row) {
return row.AccountName;
}
}).result(function (event, data, formatted) {
if(data){
$("<input name=\"AccountIds\" type=\"hidden\" />").val(data.AccountId).appendTo("#SpendExportForm");
} }).blur(function () {
var accName = $(this).val();
$("input[name=AccountIds]").each(function(){
var id=parseInt($(this).val());
var name=$.grep(Accounts,function(row){return row.AccountId==id;})[0].AccountName;
if(!new RegExp("(^"+name+",)|(,"+name+",)","i").exec(accName)){
$(this).remove();
}
});
return true;
}).keyup(function () {
if($.trim($(this).val())==""){
$("input[name=AccountIds]").remove();
}
});

jquery文档

数组的处理

                var idsa=[];
$("input[name=AccountIds]").each(function(){
idsa.push($(this).val());
});
                var d = $("#WalletIds").select2('data');
var idsw = $.map(d, function (v, i) {
return v.id;
});

  

  

正则的处理

                  if(!new RegExp("(^"+name+",)|(,"+name+",)","i").exec(accName)){
$(this).remove();
}

  

数组过滤

var name=$.grep(Accounts,function(row){return row.AccountId==id;})[0].AccountName;

  

 

form隐藏域,form提交

                $("#SpendExportForm").html("");
var d = $("#WalletIds").select2('data');
var ids = $.map(d, function (v, i) {
$("<input type=\"hidden\" name=\"WalletIds\" />").val(v.id).appendTo("#SpendExportForm");
}); $("input[name=AccountIds]").each(function(){
$("<input type=\"hidden\" name=\"AccountIds\" />").val($(this).val()).appendTo("#SpendExportForm");
}); $("<input type=\"hidden\" name=\"showAdDistribution\" />")
.val( $("#showAdDistribution")[0].checked).appendTo("#SpendExportForm"); $("#SpendExportForm").submit();

  

 

最新文章

  1. Spring学习记录(二)---容器和bean属性配置
  2. [Android]官网《UI/Application Exerciser Monkey》中文翻译
  3. 引用iScroll.js实现上拉和下拖刷新
  4. jQuery知识点总结(第四天)
  5. 使用canvas绘制时钟
  6. igbinary vs serialize vs json_encode
  7. HTML页面实现返回顶部效果 go to top
  8. 利用java读写Excel文件
  9. c#与vb.net在App_Code里面编译要通过,需要以下web.config的配置
  10. Ecshop布局参考图
  11. ant_0105
  12. 修改wampsever默认密码
  13. Redis的使用初探
  14. NB学校的NB课程的NB教材——CSAPP
  15. [硬件]_ELVE_STLINK下载出现nternal command error问题
  16. Other Problems
  17. 字符串全部转换为大写用str.toUpperCase()方法
  18. 用mac的chrome浏览器调试Android手机的网页
  19. DOS 配置IP地址
  20. 【Android】ProgressBar

热门文章

  1. OpenCV LK光流法测试
  2. golang学习笔记17 爬虫技术路线图,python,java,nodejs,go语言,scrapy主流框架介绍
  3. Django后端项目----restful framework 认证源码流程
  4. strcpy和memcpy,memmove函数的区别
  5. Android平台MediaCodec避坑指北
  6. myBatis框架之入门(一)
  7. P1357 花园
  8. 使ipconfig命令结果更整洁
  9. gdb调试程序函数名为问号,什么原因?step by step解决方案
  10. Atlas读写分离[高可用]