简体   繁体   English

jQuery multi待办事项列表

[英]Jquery multi to do list accordion

I am using jquery accordion, java script and html5, trying to make it so that each section is a lists name. 我正在使用jquery手风琴,java脚本和html5,试图使它成为每个部分都是一个列表名称。 Then within that section make so that you can add or remove from the list in that section. 然后在该部分中进行创建,以便您可以在该部分的列表中添加或删除。 So you can see what I am doing here is my fiddle . 因此,您可以看到我在这里正在做的是我的小提琴

I think the problem is here: 我认为问题出在这里:

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);
}

It was working as just a single to-do list. 它只是一个待办事项清单。 Now however I can not seem to get it to work. 但是现在我似乎无法使其正常工作。 Maybe I'm just to tired. 也许我只是累了。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

Looks like you need to assign the functions to an object. 看起来您需要将功能分配给对象。

Here is a fiddle which attaches them to window (not good) which fires the event. 这是一个小提琴,将它们附加到触发事件的窗口 (不好)上。

I suggest you create a javascript object you can call the functions on 我建议您创建一个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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM