在输入文本后如何在同一字段中追加输入 [英] How to append input in the same field after entering text in it
本文介绍了在输入文本后如何在同一字段中追加输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个输入字段,我想在输入文本的同时追加它的文本,并且保留之前的值。
I have an input field and I want to append its text while typing in it and persisting the previous value in it
b
$ b
Following is the code
<input type="text" id="txt1" name="type_name" value="Value1-" onchange="dosomething()">
我想要的是当用户开始输入时,输入字段的起始文本应该保留在那里, Value1-并在其中附加文字,如Value1-3433。
What I want is when the user starts typing it the starting text of input field should remain there which is "Value1-" and append the text in it like "Value1-3433".
我希望你能对我的观点有所帮助。
I hope you get my point a little help on this will be appreciated.
推荐答案
这就是你想要的吗?
jQuery
$ b
jQuery
$('#txt1').on('keyup',function(){
console.log($(this).val().substr( 0 , 7)) ;
if($(this).val().substr( 0 , 7) != "Value1-") {
$(this).val('Value1-');
}
});
HTML
HTML
<input type="text" id="txt1" name="type_name" value="Value1-" >
这篇关于在输入文本后如何在同一字段中追加输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文