编辑我在表单字段中提交的项目

时间:2016-03-28 03:34:57

标签: javascript jquery html css html5

  • 我正在尝试编辑我在表单字段中提交的项目...
  • 在我提交它之后编辑它不更新特定项目...
  • 你知道怎么解决它......
  • 提供以下代码......

http://codepen.io/gborbonus/pen/grRjjy?editors=1011

$('#localStorageTest').submit(function(e) {
    e.preventDefault();
    var email = $('#email').val();
    var name = $('#name').val();
    var message = $('#message').val();
    var div = "<div><span>"+name+"</span><span >"+email+"</span><span>"+message+"</span><input type='button' value='Edit' name='editHistory'><input type='button' value='Delete' name='deleteHistory'></div>";  //add your data in span, p, input.. 
    //alert(div);

    $('.gettingValues').append(div); //apendd the div
    $('#localStorageTest')[0].reset(); //clear the form 
    localStorage.clear();
 });

1 个答案:

答案 0 :(得分:0)

你可以试试这个.. 您应该在将内容附加到div之前清空div。

$(document).ready(function() {
  $('#localStorageTest').submit(function(e) {
    e.preventDefault();
    var email = $('#email').val();
    var name = $('#name').val();
    var message = $('#message').val();
    var div = "<div><span>"+name+"</span><span >"+email+"</span><span>"+message+"</span><input type='button' value='Edit' name='editHistory'><input type='button' value='Delete' name='deleteHistory'></div>";  //add your data in span, p, input.. 
    //alert(div);

    $('.gettingValues').empty();//clear all the content.

    $('.gettingValues').append(div); //apendd the div
    $('#localStorageTest')[0].reset(); //clear the form 
    localStorage.clear();
 });