我有一个选择字段,我正在尝试获取所选 HTML 中的 HTML。它一直返回为未定义。
我读过一些答案,说要使用 .val() 函数,但值和 HTML 不同,所以它不起作用。
HTML:
<select id="my_SiteUsers" style="width:250px;" onchange="RefreshGroupLists()">
<option value='default' disabled="disabled">Select a user</option>
</select>
JS:
var userText;
userText = $('#my_SiteUsers').html();
//check if default user selected alert(user);
if(user!="default"){
var removeConfirm = confirm("You are about to delete "+userText+"from SharePoint. Are you sure?");
if(removeConfirm){
$.SPServices({
operation:"RemoveUserFromSite",
userLoginName: user,
async:true
});
}
}
}
最佳答案
所以你需要的实际上是text()
var userText = $("#my_SiteUsers option:selected").text();
html()
将返回 undefined,因为选项元素内实际上没有 HTML。
关于javascript - 尝试从选项元素获取 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19102536/