JQuery TextExt 控件使用
官网:http://www.textextjs.com
兼容浏览器:火狐、IE9+、谷歌
$(document).ready(function() {
function bindTextArea() {
$("textarea:last").textext({
plugins: 'autocomplete tags prompt ajax arrow',
tagsItems: [],
prompt: '添加参与人...',
ajax: {
url: '/library/data/uid.json',
dataType: 'json',
cacheResults: true
}
})
.bind('isTagAllowed', function(e, data) {
if ($(e.target).textext()[0]._plugins.tags._formData.toString().indexOf(data.tag) != -1)
data.result = false;
});
}
$(_t).insertBefore(html);
}
//有效性验证最难实现,搞了半天
var isvalid = true;
$("input:[name='txtparuser']").each(function() {
if ($(this).val() == "" || $(this).val() == "[]") {
alert("请选择参与人!");
isvalid = false;
return false;
}
});
return isvalid;
}
</div>
json需要是这样格式的,因为这个控件不能存ID,所以ID放到括号里面了
"背包客(2)",
"rose(4)",
"snowbaby(12)"
]
using System.Text.RegularExpressions;
//如果存在多个textarea,用正则分割,如["rose(2)"],["mike(3)","baby(6)"]
string[] rs = Regex.Split(GetString("txtparuser"), @"(?<=\]),(?=\[)");
int i=0;
foreach (string s in career)
{
Hashtable caht = new Hashtable();
caht.Add("Career", s);
caht.Add("PartUser", rs[i]);
parternerlist.Add(caht);
i++;
}
HttpContext.Current.Session["parternerlist"] = parternerlist;
List<Hashtable> parternerlist = (List<Hashtable>)System.Web.HttpContext.Current.Session["parternerlist"];
System.Web.HttpContext.Current.Session.Remove("parternerlist");
if (parternerlist != null && parternerlist.Count > 0)
{
foreach (Hashtable element in parternerlist)
{
string[] paruserid= new string[4]{"0","0","0","0"} ;string[] arr = Regex.Replace(element["PartUser"].ToString(), @"[^\d,]+", "").Split(',');
Array.Copy(arr, paruserid, arr.Length);
BLL.addPostParterner(postid, element["Career"].ToString(), Convert.ToInt32(paruserid[0] == "" ? "0" : paruserid[0]), Convert.ToInt32(paruserid[1] == "" ? "0" : paruserid[1]), Convert.ToInt32(paruserid[2] == "" ? "0" : paruserid[2]), Convert.ToInt32(paruserid[3] == "" ? "0" : paruserid[3]));
}
}