【发布时间】:2016-04-02 21:05:36
【问题描述】:
所以我试图让它每次你点击一个文本字段时,它都会变成一个输入字段,然后你输入你想要的任何内容,点击输入,它会变成一个文本字段,然后这个过程就开始了重新来过。我能够让它运行,但只有一次。我怎样才能让它运行多次,以便我可以不断更改文本值?
<p class="text">Text</p>
$(".text").click(function() {
$(this).replaceWith("<input type='text' class='text'>");
$(".text").select();
$(".text").keypress(function(e) {
if (e.which == 13) {
var textVal = $(".text").val();
$(".text").replaceWith("<p class='text'>" + textVal + "</p>");
}
});
});
【问题讨论】:
标签: javascript jquery text input