【发布时间】:2014-07-25 11:06:58
【问题描述】:
用户应该能够更改名称,然后确认更改。我无法使用此代码将其存档,因为当我单击确认时,它会像以前一样返回。 我错过了什么?
有没有更好的方法来把它放在一起(我敢肯定有一个)?
请查看demo,您还可以在其中看到changeElementTypefunction
js:
$('.replace').on('click', function () {
$("h2").changeElementType("textarea");
$('.replace').hide();
$('.confirm').show();
//Confermation of the change
$('.confirm').bind('click', function () {
$('.replace').show();
$('.confirm').hide();
$("textarea").changeElementType("h2");
});
if ($('textarea:visible')) {
$(document).keypress(function (e) {
if (e.which == 13) {
alert('You pressed enter!');
$("textarea").changeElementType("h2");
$('.replace').css('opacity', '1');
}
});
}
});
【问题讨论】:
-
但是你没有对输入的值做任何事情
-
@mitomed 是的,注意到了!但不确定如何获得此值
-
我认为你的代码没问题,只是你应该对输入的值做一些事情,比如jsfiddle.net/7gXz7
-
@mitomed 看起来不错!!!你知道如何设置限制或其他东西吗?但是感谢这个
-
什么限制,也许可以编辑问题并更新你真正想要实现的目标
标签: javascript jquery onclick textarea