使用jQuery选择器和setSelectionRange不是一个函数 [英] Using jQuery selector and setSelectionRange is not a function

查看:233
本文介绍了使用jQuery选择器和setSelectionRange不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在下面组装了一个基本的jfiddle。由于某种原因,我的选择器用于检索textarea框以设置值,但选择器不能使用setSelectionRange函数。在控制台上你会发现.setSelectionRange不是函数的错误。

I have assembled a basic jfiddle below. For some reason my selector works to retrieve the textarea box to set the value, but the selector doesnt work to use the setSelectionRange function. On the console you'll find an error for .setSelectionRange is not a function.

http://jsfiddle.net/dMdHQ/6/

代码(请参阅jfiddle):
selector.setSelectionRange(carat,carat);

code(please refer to jfiddle): selector.setSelectionRange(carat,carat);

推荐答案

setSelectionRange(carat,carat)不是jquery对象上的方法。您想在DOM元素上使用它。所以试试:

setSelectionRange(carat,carat) is not a method on jquery object. You want to use it on DOM element. So try:

selector[0].setSelectionRange(carat,carat); //use `[0]` or .get(0) on the jquery object

参见参考

这篇关于使用jQuery选择器和setSelectionRange不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆