jquery - 在keyDown中从输入中删除文本 [英] jquery - in keyDown erase text from input
问题描述
我有一个输入框,我在网站上有一些文本
< input type =textvalue =输入名称/>
现在我需要补充说,当用户开始输入内容(输入第一个字母)时,我的文字将消失,他将能够输入他想要的输入。
我尝试过:
$('#input') .keypress(function(){
$(this).val();
});
但是,用户只能输入一个字母cuz,它继续删除文本。
如何做?
谢谢
您可以使用占位符来执行此操作
演示:
http://jsfiddle.net/9VhYZ/
某些浏览器还不支持此功能,添加后备也可以支持跨浏览器的一个好主意:
http://davidwalsh.name/html5-placeholder
更新:
您可以按照以下要求执行所需操作:
http://jsfiddle.net/9VhYZ/1/
<$一个(keydown,function(){
$(this).val();
}); p $ p>
$
I have a input box that i have some text in site
<input type="text" value="Enter Name"/>
Now i need to add that when the user starts typing in something (enters the first letter), my text will disappear and he will be able to enter the input he wants.
I tried doing:
$('#input').keypress(function () {
$(this).val("");
});
But then the user can only enter one letter cuz it keeps on deleting the text.
How can this be done?
Thanks
You can do this by using a placeholder
Demo: http://jsfiddle.net/9VhYZ/
Some browser doesn't yet support this, adding a fallback could also be a good idea to support it cross browser: http://davidwalsh.name/html5-placeholder
UPDATE: You can do what you ask for like this: http://jsfiddle.net/9VhYZ/1/
$('#input').one("keydown", function () {
$(this).val("");
});
这篇关于jquery - 在keyDown中从输入中删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!