使表单/div 可编辑
您好,我有大约 6 个目前只读的字段。我现在必须使它们可编辑。所以我正在考虑使用一个图像/按钮,单击它会触发编辑功能。因此,单击该按钮时,我将加载一个包含文本框的表单,这使得这些字段可编辑。我正在尝试使用 JQuery 执行此操作,但我无法理解如何从只读字段中获取可编辑表单。
如何加载一个具有与我们之前的字段相同的字段并允许用户编辑的表单?
这是我现在的代码,我必须将可编辑表单加载到 id 中。
<div id="student-infomercial">
<ul>
<label>Name:</label>
<div ><?php echo $name; ?></div>
</li>
<li>
<label>Age:</label>
<div ><?php echo $age; ?></div>
</li>
<li>
<label>Country:</label>
<div ><?php echo $country; ?></div>
</li>
<li>
<label>State:</label>
<div ><?php echo $state; ?></div>
</li>
<li>
<label>City:</label>
<div ><?php echo $city; ?></div>
</li>
<li>
<li>
<label>Zip:</label>
<div ><?php echo $zip; ?></div>
</li>
</ul>
</div>
Hello I have around 6 fields which are read only presently. I now would have to make them editable. So I am thinking of having one image/button, which onclick would trigger the edit functionality. So onclick of that button, I would have a form load up which would have the textboxes, which makes those fields editable. I am trying to do this with JQuery, I am unable to understand on how to get a editable form out of read only fields.
How is it possible to load up a form which would have same fields as the one we had earlier and allows the users to edit?
This is my present code, I would have to load my editable form into the id.
<div id="student-infomercial">
<ul>
<label>Name:</label>
<div ><?php echo $name; ?></div>
</li>
<li>
<label>Age:</label>
<div ><?php echo $age; ?></div>
</li>
<li>
<label>Country:</label>
<div ><?php echo $country; ?></div>
</li>
<li>
<label>State:</label>
<div ><?php echo $state; ?></div>
</li>
<li>
<label>City:</label>
<div ><?php echo $city; ?></div>
</li>
<li>
<li>
<label>Zip:</label>
<div ><?php echo $zip; ?></div>
</li>
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
所以我猜你是在问如何将你的元素转换成?你可以做到,但可能会很麻烦。如果我是你,我会改为使用以下 html:
然后在你的 javascript 中:
如果你坚持使用
那么你将不得不转换
在某些事件上将标签添加到
标签。
还有很多方法可以实现您的目标;以上只是我脑海中浮现的解决方案。
So I guess you're asking how to transform your element into ? You can do it, but it probably will be too much trouble. If I were you I would have following html instead:
then in your javascript:
If you insist on using
<div>
then you will have to transform the<div>
tags to<input>
tags upon some event.There are many many more ways you can achieve your goal; the above is just the solution that pops into my mind.
开始使用 https://github.com/tectual/jQuery-Editable。它有一个 data-for 属性。
基本上,您可以使用字段的 data-for 属性定义显示 div/标签,然后调用 $('formCssSelector').editables() 将使它们全部可编辑。并设置 onFreeze 函数,您可以定义它以使用您首选的验证系统,如果所有字段均有效,则使用 $.ajax
示例页面提交 jquery 可编辑 html 5 技术
Start using https://github.com/tectual/jQuery-Editable. it has a data-for attribute.
Basically you define the display div/label with data-for attribute for a field and then calling $('formCssSelector').editables() will make them all editable. and setting onFreeze function you can define to use your preferred validation system and if all fields are valid submit using $.ajax
sample page for jquery editable html 5 technique
您只是问如何取消禁用属性吗?
Are you just asking how to unset the disabled attribute?
您看过 jeditable 吗?我认为它会很好地满足您的需求。
编辑以解决评论。
这是一个起点
Have you taken a look at jeditable? I think it will work well for what you want.
EDIT to address comment.
Here is a starting point
因此,另一个选择是使用可编辑表单创建一个完全独立的页面。使用如下代码表示 form.php:
然后在显示页面上,您可以添加一个名为 edit 的按钮,并使用 AJAX 加载表单,如下所示:
这样整个显示都将替换为表单。然后,您可以在表单上添加取消按钮以返回到显示。
So another option is to create an entirely separate page with the editable form. Say form.php with code like this:
Then on your display page you can add a button named edit and load the form using AJAX like this:
This way the entire display is replaced with a form. You can then add a cancel button on the form to go back to the display.