欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery設(shè)置聚焦并使光標(biāo)位置在文字最后的實(shí)現(xiàn)方法

 更新時(shí)間:2016年08月02日 09:56:21   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇jQuery設(shè)置聚焦并使光標(biāo)位置在文字最后的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

如下所示:

$.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);
};

以上這篇jQuery設(shè)置聚焦并使光標(biāo)位置在文字最后的實(shí)現(xiàn)方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • jQuery 實(shí)現(xiàn)左右兩側(cè)菜單添加、移除功能

    jQuery 實(shí)現(xiàn)左右兩側(cè)菜單添加、移除功能

    本文通過(guò)實(shí)例代碼給大家分享了jQuery 實(shí)現(xiàn)左右兩側(cè)菜單添加、移除功能,需要的朋友參考下吧
    2018-01-01
  • jQuery實(shí)用函數(shù)用法總結(jié)

    jQuery實(shí)用函數(shù)用法總結(jié)

    這篇文章主要介紹了jQuery實(shí)用函數(shù)用法總結(jié),匯總了jQuery常用的函數(shù)及相關(guān)技巧,需要的朋友可以參考下
    2014-08-08
  • 最新評(píng)論