使用jquery/javascript在文本框中的第一位置限制空间 [英] restrict space at first position in textbox using jquery/javascript
本文介绍了使用jquery/javascript在文本框中的第一位置限制空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到一种情况,我需要限制用户在TextBox的开头输入空格. 我能够限制TextBox中的空间输入.但是没有任何关于不允许进入第一位置的线索.
I have a situation where I need to restrict users from entering space in beginning of a TextBox. I am able to restrict space entry in TextBox. But not having any clues about not allowing at first position.
我正在寻找使用JavaScript或jQuery的解决方案.任何帮助将不胜感激.
I am looking for a solution using JavaScript or jQuery. Any help would be appreciated.
推荐答案
keypress
事件解决方案:
keypress
event solution:
$("input").on("keypress", function(e) {
if (e.which === 32 && !this.value.length)
e.preventDefault();
});
演示: http://jsfiddle.net/pdzBy/
这篇关于使用jquery/javascript在文本框中的第一位置限制空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文