官网:http://www.textextjs.com
兼容浏览器:火狐、IE9+、谷歌
<script src="/js/textExt.js"></script>
<script language="javaScript"> $(document).ready(function() {
$("#tdAddcry").live("click", bindTextArea);
}); 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; }); }
function addCanYuRen(_t) {
var html ="<textarea name='txtparuser' rows='1' cols='50'></textarea>";
var trl = $(".addCanyuren"); $(_t).insertBefore(html);
}
//有效性验证最难实现,搞了半天
function checkvalid() { var isvalid = true; $("input:[name='txtparuser']").each(function() { if ($(this).val() == "" || $(this).val() == "[]") { alert("请选择参与人!"); isvalid = false; return false; } }); return isvalid; }
< body >
< div >
< div class="addCanyuren"> </div >
< span id ="tdAddcry" onclick ="addCanYuRen(this)" style ="color:#0033FF; cursor:pointer; margin:5px; font-weight:bold;" >添加参与人 </ span >
</div>
</ body >
json需要是这样格式的,因为这个控件不能存ID,所以ID放到括号里面了
[ "背包客(2)", "rose(4)", "snowbaby(12)" ]
// 后台 using System.Text.RegularExpressions; // 如果存在多个textarea,用正则分割,如["rose(2)"],["mike(3)","baby(6)"]
List<Hashtable> parternerlist = new List<Hashtable>();
string[] career = GetString( " txtcareer ").Split( ' , '); 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])); } }