关于JavaScript 获取文本框光标的坐标

关于JavaScript 获取文本框光标的坐标,第1张

$("input:focus") //光标所在input元素的位置

$("textarea:focus")//光标所在textarea元素的位置

$("input:focus,textarea:focus")//光标所在元素的位置

网页可见区域宽: documentbodyclientWidth

网页可见区域高: documentbodyclientHeight

网页可见区域宽: documentbodyoffsetWidth (包括边线的宽)

网页可见区域高: documentbodyoffsetHeight (包括边线的高)

网页正文全文宽: documentbodyscrollWidth

网页正文全文高: documentbodyscrollHeight

网页被卷去的高: documentbodyscrollTop

网页被卷去的左: documentbodyscrollLeft

网页正文部分上: windowscreenTop

网页正文部分左: windowscreenLeft

屏幕分辨率的高: windowscreenheight

屏幕分辨率的宽: windowscreenwidth

屏幕可用工作区高度: windowscreenavailHeight

屏幕可用工作区宽度: windowscreenavailWidth

网页可见区域宽: documentbodyclientWidth

网页可见区域高: documentbodyclientHeight

网页可见区域宽: documentbodyoffsetWidth (包括边线的宽)

网页可见区域高: documentbodyoffsetHeight (包括边线的高)

网页正文全文宽: documentbodyscrollWidth

网页正文全文高: documentbodyscrollHeight

网页被卷去的高: documentbodyscrollTop

网页被卷去的左: documentbodyscrollLeft

网页正文部分上: windowscreenTop

网页正文部分左: windowscreenLeft

屏幕分辨率的高: windowscreenheight

屏幕分辨率的宽: windowscreenwidth

屏幕可用工作区高度: windowscreenavailHeight

屏幕可用工作区宽度: windowscreenavailWidth

网页可见区域宽: documentbodyclientWidth

网页可见区域高: documentbodyclientHeight

网页可见区域宽: documentbodyoffsetWidth (包括边线的宽)

网页可见区域高: documentbodyoffsetHeight (包括边线的高)

网页正文全文宽: documentbodyscrollWidth

网页正文全文高: documentbodyscrollHeight

网页被卷去的高: documentbodyscrollTop

网页被卷去的左: documentbodyscrollLeft

网页正文部分上: windowscreenTop

网页正文部分左: windowscreenLeft

屏幕分辨率的高: windowscreenheight

屏幕分辨率的宽: windowscreenwidth

屏幕可用工作区高度: windowscreenavailHeight

屏幕可用工作区宽度: windowscreenavailWidth

HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth

scrollHeight: 获取对象的滚动高度。

scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离

scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离

scrollWidth:获取对象的滚动宽度

offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度

offsetLeft:获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置

offsetTop:获取对象相对于版面或由 offsetTop 属性指定的父坐标的计算顶端位置

eventclientX 相对文档的水平座标

eventclientY 相对文档的垂直座标

eventoffsetX 相对容器的水平坐标

eventoffsetY 相对容器的垂直坐标

documentdocumentElementscrollTop

有资料可以查看。。。

//滚动条位置

function GetPageScroll() 

    var x, y; if(windowpageYOffset) 

    {    // all except IE    

        y = windowpageYOffset;    

        x = windowpageXOffset; 

    } else if(documentdocumentElement && documentdocumentElementscrollTop) 

    {    // IE 6 Strict    

        y = documentdocumentElementscrollTop;    

        x = documentdocumentElementscrollLeft; 

    } else if(documentbody) {    // all other IE    

        y = documentbodyscrollTop;    

        x = documentbodyscrollLeft;   

    } 

    return {X:x, Y:y};

}

<title>Js获取适时获取鼠标坐标值并显示</title>

<script type="text/javascript">

var getCoordInDocumentExample = function(){

var coords = documentgetElementById("coords");

coordsonmousemove = function(e){

var pointer = getCoordInDocument(e);

var coord = documentgetElementById("coord");

coordinnerHTML = "X,Y=("+pointerx+", "+pointery+")";

}

}

var getCoordInDocument = function(e) {

e = e || windowevent;

var x = epageX || (eclientX +

(documentdocumentElementscrollLeft

|| documentbodyscrollLeft));

var y= epageY || (eclientY +

(documentdocumentElementscrollTop

|| documentbodyscrollTop));

return {'x':x,'y':y};

}

windowonload = function(){

getCoordInDocumentExample();

};

</script>

<div id="coords" style="width:500px;height:200px;background:#F2F1D7;border:2px solid #0066cc;">

请在此移动鼠标。

</div>

<br />

<div id="coord" style="width:500px;border:2px solid #336699;"> </div>

1、首先打开我们测试的编辑工具 我这里使用的是Eclipse。

2、首先我们新建一个测试项目然后新建一个indexhtml、basicjs和basiccss文件。

3、js修改html文件中div的style中值来修改div的高度 HTML文件中的文件代码。

4、接下来我们就使用js修改高度。

5、这时我们敲js中的代码 获取div1的id 使用css属性对应的style属性然后设置高度。

6、使用js修改CSS文件中的div的height的值 HTML文件中的代码。

7、样式表css文件中的代码如图所示  运行项目之后 你会看到两个div的高度是一样的。

8、然后我们是在js文件中获取div1的id属性 然后使用objstylecssTest来修改嵌入式的css。

9、然后运行项目之后 两次结果都是一样的 div的高度改变了  。

以上就是关于关于JavaScript 获取文本框光标的坐标全部的内容,包括:关于JavaScript 获取文本框光标的坐标、javascript 节点获取坐标(相对于屏幕\页面\...)、怎么用JavaScript获取当前网页滚动条的坐标呢等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9549781.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存