是否可以控制输入键入在焦点处开始的位置?
e.g。
<input type="text" value="(+44)" id="phone_number" />
我需要用户的输入在现有值之后开始,但是将该选项留给退格并删除。
类似的东西:
$(document).ready(function(){
$('#phone_number').focus(function(){
//place type start after whatever value already exists
});
});
答案 0 :(得分:1)
这也可以帮助您保持格式化的输入字段
http://digitalbush.com/projects/masked-input-plugin/
jQuery(function($){
$("#phone_number").mask("(+44)999999");
});
我使用9只添加数值,否则你可以*添加任何东西
答案 1 :(得分:1)
如果你想使用jQuery,你可以这样做:
$("input").focus(function () {
var val = this.value;
var $this = $(this);
$this.val("");
setTimeout(function () {
$this.val(val);
}, 1);
});
<强> DEMO 强>