Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var Phone = function(input) {
var $this = this;
this.input = input;
this.init = function(options) {
this.option = this.cloneObj(options);
this.bild();
};
this.bild = function() {
var val = this.input.val().split(' ');
var val1 = val[0];
var val2 = val[1];
this.input1 = $('<input>').keydown(this.keydown).blur(this.setValue).addClass('span1').val(val1).attr('type', 'text').attr('placeholder', 'код');
this.input2 = $('<input>').keydown(this.keydown).blur(this.setValue).addClass('span2').val(val2).attr('type', 'text').attr('placeholder', 'номер телефона');
this.input.hide().after(this.input1, this.input2);
};
this.keydown = function(event) {
if (event.which < 58 || (event.which > 95 && event.which < 106)) {
return true;
}
event.preventDefault();
};
this.setValue = function() {
$this.input.val($this.input1.val()+' '+$this.input2.val());
};
this.cloneObj = function(obj) {
var ret = {};
for ( var k in obj )
ret[k] = obj[k];
return ret;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment