显示提交的值 [英] displaying the submitted values
问题描述
我正在尝试更新在表单中输入的表单值以显示为列表。我试图获取表单值并使用本地存储显示值,但我不知道如何显示输入的值在 div
标记类的 gettingValues
I am trying to update the form values which I enter in the form to show as a list. I am trying to get the form values and display the values using local storage but I am not sure how to display the entered values inside a div
tag with a class of gettingValues
.
你能告诉我怎么做吗?我在下面提供我的代码。我也把它放在Codepen: http://codepen.io/anon/pen/ PNjQRQ?editors = 1010
Can you tell me how to do it? I am providing my code below. I have put it in a Codepen too: http://codepen.io/anon/pen/PNjQRQ?editors=1010
<div class="gettingValues"> getting form values
<input data-name="edit" type="button" value="Edit" name="editHistory">
<input data-name="delete" type="button" name="deleteHistory" value="Delete">
</div>
推荐答案
$('#localStorageTest').submit(function() {
localStorage.clear();
});
更改为:
$('#localStorageTest').submit(function(e) {
e.preventDefault();
var div = "<div><span>"+$('#name').val()+"</span><span>"+$('#email').val()+"</span></div>"; //add your data in span, p, input..
$('.gettingValues').append(div); //apendd the div
$('#localStorageTest')[0].reset(); //clear the form
localStorage.clear();
});
但是如果你想要点击编辑或删除按钮并触发一些功能,您必须附加一个绑定功能并设置一个'id'或唯一标识符以知道哪个用户编辑/删除。
But if you want then to click in 'edit' or 'delete' button and trigger some function, you must attach a bind funtion and set a 'id' or a unique identifier to know which user edit/delete.
如果您还想存储提交的用户,可以添加 $。get / $ .post
函数。
If you want also to store the user submited, you could add a $.get / $.post
function.
希望它有帮助!
这篇关于显示提交的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!