Jquery相关插件
$("#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(); } });
数组的处理
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();