Home>

As follows:

$.fn.setcursorposition=function (position) {
if (this.lengh == 0)
return this;
return $(this) .setselection (position, position);
};
$.fn.setselection=function (selectionstart, selectionend) {
if (this.lengh == 0)
return this;
input=this [0];
if (input.createtextrange) {
var range=input.createtextrange ();
range.collapse (true);
range.moveend ("character", selectionend);
range.movestart ("character", selectionstart);
range.select ();
} else if (input.setselectionrange) {
input.focus ();
input.setselectionrange (selectionstart, selectionend);
}
return this;
};
$.fn.focusend=function () {
this.setcursorposition (this.val (). length);
};
  • Previous AngularJS basic ng-keyup directive simple example
  • Next JavaScript implements copying articles to automatically add copyright