如何在列表中添加删除按钮?

时间:2016-07-20 11:57:48

标签: javascript html

您好我有html javasicript开始的项目,但我尝试了一些事情。 我想添加列表删除按钮,但我不知道如何为每一行添加删除按钮?

<!DOCTYPE html>
<html lang="en">

<body>
  <header><h1></h1></header>
  <section>
   
    <form action="#" method="post">
      <div>
        <label for="newitem">Add item</label>
        <input type="text" name="newitem" id="newitem" 
               placeholder="new item" />
        <input type="submit" value="Add" />
      </div>
    </form>
     <ul id="todolist"></ul>
  </section>
  
<script>
(function(){

  var todo = document.querySelector( '#todolist' ),
      form = document.querySelector( 'form' ),
      field = document.querySelector( '#newitem' );
    
  form.addEventListener( 'submit', function( ev ) {
    var text = field.value;
    if ( text !== '' ) {
      todo.innerHTML += '<li>' + text + '</li>';
      field.value = '';
      //field.focus();
    }
    ev.preventDefault();
  }, false);



})();
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:6)

&#13;
&#13;
public class CreateXML {

public CreateXML(ArrayList<Integer> array,String name){
    try{
    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    DocumentBuilder db=dbf.newDocumentBuilder();

    String path="file"+name+".xml";
    File xmlfile=new File(path);
    if(xmlfile.exists()){
        xmlfile.delete();
        System.out.println("There was this file and it is deleted.");
    }

    Document doc=db.newDocument();

    Element rootElement=doc.createElement("numberList");
    doc.appendChild(rootElement);
        for (int i = 0; i < array.size(); i++) {
            Element staff=doc.createElement("number");
            rootElement.appendChild(staff);

            Attr attr=doc.createAttribute("id");
            attr.setValue(Integer.toString(i));
            staff.setAttributeNode(attr);
            staff.setTextContent(Integer.toString(array.get(i)));
        }

    TransformerFactory tf=TransformerFactory.newInstance();
    Transformer t=tf.newTransformer();

    DOMSource source=new DOMSource(doc);
    StreamResult result=new StreamResult(xmlfile);

    t.transform(source, result);
    }catch(Exception e){
        e.printStackTrace();
        }
    }

}
&#13;
&#13;
&#13;