我正在使用jquery accordion,java脚本和html5,尝试使每个部分都是列表名称。然后在该部分中进行制作,以便您可以在该部分的列表中添加或删除。所以你可以看到我在做什么here is my fiddle。
我认为问题在于:
function add_listitem(key,item)
{
var li = document.createElement('li');
li.appendChild(document.createTextNode(item));
li.setAttribute("data-key,key");
var but = document.createElement('button');
but.appendChild(document.createTextNode('Delete'));
but.onclick = remove_item;
li.appendChild(but);
document.getElementById('todo_list').appendChild(li);
}
它只是一个单一的待办事项列表。但现在我似乎无法让它发挥作用。也许我只是累了。非常感谢任何帮助。
答案 0 :(得分:0)
看起来您需要将功能分配给对象。
发生事件的Here is a fiddle which attaches them to window(不好)。
我建议你创建一个javascript对象,你可以调用
上的函数CODE:
$('#add').click(function () {
var listnames = prompt("Please enter list name", "List 1");
$('#accordion').append('<h3><a href="#">' + listnames + '</a></h3><div id="' + listnames + '"><input onkeypress="Javascript: if (event.keyCode==13) window.add_items();" type="text" id="new_item" class="todo-input" placeholder="Add to list"></div>');
$("#accordion").accordion('destroy').accordion();
});
window.add_items = function add_items(){
//alert(this.document.activeElement.parentNode.id);
var new_item = this.document.activeElement;
alert(new_item.value);
var key = new date();