SharePoint Tips and Tricks --如何用JS向PeopleEditor填充数据
有时我们需要在客户端为PeopleEditor控件填充值,但是PeopleEditor控件生成的HTML很复杂,包含一坨乱七八糟的东西。好吧,下面的这个JavaScript函数可以为你做这个(只在SharePoint 2010测试过)。
function setPeoplePicker(pickerid, value) {
var field = $("#" + pickerid);
if (field.find('.ms-inputuserfield:visible').length > 0) {
// IE
var userlist = field.find('.ms-inputuserfield').html();
field.find('.ms-inputuserfield').html(userlist+";"+value);
field.find('img:first').click();
} else {
// FF
var userlist = field.find("textarea:first").val();
field.find("textarea:first").val(userlist + ";" + value);
}
}
$(document).ready(function () {
// setPeoplePicker("<%=CPE.ClientID%>", "CustomValue");
});