我想在按下删除图标后从引导列表中删除一个元素。 add函数在列表中添加字符串和删除图标。我打算迭代列表,检查是否单击了删除按钮,如果单击了,则删除。问题是我不知道如何访问对象ul的元素。
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
Session.Credentials.Add "*.myserver.com", "Domain\UserName", "MyPassword"
set OofAssistant = Session.Stores.DefaultStore.OutOfOfficeAssistant
OofAssistant.BeginUpdate
OofAssistant.StartTime = #12/21/2011#
OofAssistant.EndTime = #01/03/2012 9:00#
OofAssistant.State = 2 'rdoOofScheduled
OofAssistant.ExternalAudience = 1 'rdoOofAudienceKnown
OofAssistant.OutOfOfficeTextInternal = "<html><body>I am on vacation from 12/21/2001 until 01/03/2012. Please contact " & _
"<a href=""mailto:Joe.User@MyCompany.com"">Joe User</a>" & _
" if you have any questions</body></html>"
OofAssistant.OutOfOfficeTextExternal = "<html><body>I am on <b>vacation</b> until next year. </body></html>"
OofAssistant.EndUpdate
答案 0 :(得分:1)
您可以使用this
关键字和Onclick
活动。
var ul = document.getElementById("list");
function isBlank(str) {
return (!str || /^\s*$/.test(str));
}
function add()
{
if(!isBlank(document.getElementById("task").value)) {
var iCon = document.createElement('div');
var li = document.createElement("il");
var closeSpan = document.createElement("span");
iCon.className = "glyphicon glyphicon-remove";
iCon.addEventListener("onclick",remove(this));
closeSpan.setAttribute("class", "badge");
closeSpan.appendChild(iCon);
li.innerHTML = document.getElementById('task').value;
li.setAttribute("class", "list-group-item");
li.appendChild(closeSpan);
ul.appendChild(li);
}
}
function remove(_this)
{
/*Use _this to access the element you just clicked and remove elements you need to remove*/
}
答案 1 :(得分:0)
如果删除按钮位于列表项中:在删除按钮上添加一个事件侦听器,向上搜索dom以查找其父LI项,然后将其删除。
答案 2 :(得分:0)
为列表项和按钮设置属性“id”。请检查以下代码。
var ul = document.getElementById("list");
var lastId=0;
function add()
{
var entry = document.createElement('li');
entry.setAttribute('id','item'+lastid);
var button=document.createElement("button");
button.setAttribute('onClick','remove("'+'item'+lastid+'")');
entry.appendChild(button);
lastid+=1;
ul.appendChild(entry);
}
function remove(itemid){
var item = document.getElementById(itemid);
ul.removeChild(item);
}