【发布时间】:2015-08-10 20:53:42
【问题描述】:
我正在尝试实现一个编辑功能,它允许我在文本元素和表单元素之间来回切换。附加代码的当前功能是正确的,除了编辑按钮在单击“取消”后重新出现时变得不起作用。我使用事件委托来使创建的“取消”按钮起作用,但现在我需要以某种方式将其圈回顶部。
$(document).ready(function() {
$("#edit").click(function() {
var fruit = $("p").html();
var editbutton = $("#button").html();
$("#button").html("<input id='submit' type='button' value='submit' /><input id='cancel' type='button' value='cancel' />");
$("p").html("<input type='text' value='" + fruit + "' />");
$("#button").on('click', '#cancel', function() {
$("#button").html(editbutton);
$("p").html(fruit);
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<p>Apple</p>
<span id='button'><input id='edit' type='button' value=edit /></span>
【问题讨论】:
标签: javascript php jquery html