![](/img/trans.png)
[英]How to move placeholder text along with the content of a textbox in HTML?
[英]Move a default text as you type in a textbox along with text typed
默認文本為“移動”
-------------------------------------
|Move |
| |
| |
-------------------------------------
-------------------------------------
|W Move |
| |
| |
-------------------------------------
-------------------------------------
|Wo Move |
| |
| |
-------------------------------------
-------------------------------------
|Wow Move |
| |
| |
-------------------------------------
當我開始輸入字母“ w”,“ o”,“ w”時,默認文本“ Move”將向右移動,作為新字母追加到文本框中。
我搜索了一段時間,但沒有獲得正確的指針來實現這一目標。 希望得到某人將能夠為我指明正確的方向。
這是我到目前為止擁有的jsfiddle頁面, http://jsfiddle.net/jsnewbie/xmtFM/2/
謝謝你的幫助。
不確定為什么需要JavaScript才能完成此任務? 如果有人只是單擊“移動”一詞前的框,則文本框的默認功能將完全滿足您的期望。
編輯
退格鍵和@KevinB建議的有點響應
var store = $('textarea').val();
console.log(store);
var newVal = [];
$("textarea").focus(function () {
console.log(store);
}).keydown(function (e) {
var self = this;
setTimeout(function () {
if (e.keyCode !== 8) {
var curr = String.fromCharCode(e.keyCode);
newVal.push(curr);
console.log(newVal + store);
} else { // Backspace
e.preventDefault();
if (newVal.length > 0) newVal.pop();
}
$(self).val(newVal.join('') + " " + store);
}, 20);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.