
<body onload="javascript:showLoginMeg('usrId','${loginFormloginMsg}');"> //在body中定义事件
function showLoginMeg(logobj,loginMsg){
if ("" != loginMsg){
//logobjfocus();
alert(loginMsg);
documentgetElementById(logobj)focus(); //此处的logobj是一个字符串 得把他转换成对象进行焦点的定位
}
}
<pre></pre>
<pre></pre>
<div class="translator-theme-default" id="translator-floating-panel" style="bottom:auto; left:0px; right:auto; top:89px">
<div title="点击翻译" id="translator-floating-panel-button"></div>
</div>
<pre></pre>
<div class="translator-theme-default" id="translator-floating-panel" style="bottom:auto; left:545px; right:auto; top:20px">
<div title="点击翻译" id="translator-floating-panel-button"></div>
</div>
<div style="padding-top:20px">
<p style="font-size:12px;">版权声明:本文为博主原创文章,未经博主允许不得转载。</p>
</div>
js
documentgetElementById(id)focus();
例如
<input id="shan" type="text" onchange ="return gaib(thisid)"/>
function gaib(id) {
var oo=documentgetElementById(id);
if (oovalue == 3) {
alert('输入错误');
oofocus();
}
}
jquery
$("#"+id)focus();
例如
<input id="shan" type="text" onchange ="return gaib(thisid)"/>
function gaib(id) {
var oo=$("#"+id);
if (ooval() == 3) {
alert('输入错误');
oofocus();
}
}
第一、先要把这个div的定位设为 relative 或者 absolute,比如:
<div id="d1" style="margin-top: 3;margin-left: -5;width: 470;height: 25;position:relative" ></div>
第二、离浏览器头部的位置top值: documentgetElementById('d1')offsetTop+documentbodyscrollTop
left值:documentgetElementById('d1')offsetLeft;
js定位span没有id的原因有2点。
1、id和class都是自己加的,不加就没有,没有id和class时js可用documentgetElementsByTagName("span")来获取,针对哪一个就用哪个的下标,css中识别可用后代选择器或者属性选择器。
2、不用id可以用class和name。
以上就是关于JS中怎么定位焦点全部的内容,包括:JS中怎么定位焦点、js或jquery定位光标、js获取某个div离浏览器头部的位置等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)