0

我有两个变量usergroup声明。当我运行该函数removeGroupFromSite()时,它应该提醒我说请选择一个组,但变量返回为null。我认为这是因为它获得了选择的价值而不是选择的选项?如何在这些变量中获取所选选项的值?

var user, group, strHTMLSiteUsers, strHTMLSiteGroups, strHTMLAvailable, strHTMLAssigned, arrOptionsAssigned, arrGroups, arrUsers, intOpts, booMatch, booErr;

$(document).ready(function(){ 
    user = $('#my_SiteUsers');
    group = $('#my_SiteGroups');
    groupsAssigned = $("#my_SPGroupsAssigned");
    groupAvailable = $("#my_SPGroupsAvailable");
    userAssigned = $("#my_SPUsersAssigned").html("");
    userAvailable = $("#my_SPUsersAvailable").html("");

    $("button").click(function() { return false; });

    populateUsers();
    populateGroups();
});

function removeGroupFromSite(){
  //check if default group selected 
  alert('cp'+group.val());
  if(group.val() !== "default"){
    var removeConfirm = confirm("Are you sure you want to delete group: " + group.val());
    if(removeConfirm){
      $().SPServices({
        operation:"RemoveGroup",
        groupName: group,
        async:true,
        completefunc: function (xData,Status){
            alert(group + " succesfully deleted");
        }
      });
    }
  }else{
    alert("Please select a group");
  }
}

HTML

<select id="my_SiteGroups" style="width:200px;" onchange="RefreshUserLists()">
        <option value='default' disabled="disabled">Select a group</option>
      </select>
4

1 回答 1

1

简单修复

disabled="disabled"_<option>

disabled属性不携带来自DOM的值,因为它被禁用。

Reference

禁用

此布尔属性指示表单控件不可用于交互。特别是,click 事件不会在禁用的控件上调度。此外,禁用控件的值不会与表单一起提交。如果 type 属性的值是隐藏的,则忽略此属性。

于 2013-10-01T05:12:39.517 回答