我有一个选择,当删除项目而不是刷新页面时,我需要重置其中的值。默认选项不断被删除。
HMTL:
<select id="my_SiteGroups" style="width:200px;">
<option value='default' disabled="disabled">Select a group</option>
</select>
JS:
group = $('#my_SiteGroups');
function populateGroups(){
//Populate the group list
strHTMLSiteGroups = "";
group.empty(':not(:first-child)');
$().SPServices({
operation: "GetGroupCollectionFromSite",
async: true,
completefunc: function(xData, Status) {
$(xData.responseXML).find("Group").each(function() {
strHTMLSiteGroups += "<option value='" + $(this).attr("Name") + "'>" + $(this).attr("Name") + "</option>";
});
group.append(strHTMLSiteGroups);
}
});
}
基本上 populateGroups 将所有内容添加到选择中,但是当我删除用户时,我希望它再次运行。删除已删除的选项。我用它来删除:
function removeGroupFromSite(){
//check if default group selected
if(group.val() != null){
var removeConfirm = confirm("Are you sure you want to delete: " + group.val());
if(removeConfirm){
$().SPServices({
operation:"RemoveGroup",
groupName: groupValue,
async:true,
completefunc: function (xData,Status){
alert(groupValue + " succesfully deleted");
group.val('default');
populateGroups();
$("#my_SPUsersAssigned").empty();
$("#my_SPUsersAvailable").empty();
}
});
}
}else{
alert("Please select a group");
}}
编辑:使用 Javasript 附加默认选项会更容易吗?