我正在尝试使用 prepend() 在输入文本之前放置文本。
这是我的尝试:
但它不起作用..
任何的想法?
哈维
您不想使用 prepend,它将给定的文本添加到输入中,使您的文本出现在输入中。就像是:
<input type='text'>Your text</input>
您需要使用 before which 创建
Your Text <input type='text'/>
看到这个jsFiddle
您也可以这样做,这会将文本添加为输入父项的第一项。
$('input').keypress(function(e) {
if(e.keyCode == 13) {
console.log($(this));
$(this).parent().prepend("<p>fasf</p>");
alert('You pressed enter!');
}
});