【发布时间】:2011-12-10 16:25:51
【问题描述】:
我有一个文本输入,需要一个 url 作为值(完整的 http://),如果用户不自己编写它,我希望它自动添加。我的代码如下,
jQuery
$('.txtUrl').keypress(function(e) {
if(e.keyCode == 13) {
var ini = $(this).val().substring(0,3);
if (ini === 'http'){
$.noop()
}
else {
// get value from field
var cur_val = $(this).val();
// do with cur_val
$(this).val('http://' + cur_val);
}
}
});
HTML
<input type="text" class="txtUrl" />
【问题讨论】:
标签: jquery forms validation textinput