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,然后采用attr方法来获取其值:
假如说:有一段Html代码:
[html] view plaincopy
<div class="comment" id="22">
<div class="comment_detail" style="display: block; ">
<div class="comment_my"><textarea class="comment_text" style="height: 16px; "></textarea></div>
<div class="comment_text_bottom" style="display: none; ">
<div class="comment_emotion"><a href="javascript:void(0)" class="comment_emotion_button">表情</a>
<div class="comment_emotion_detail" style="display: none; ">
</div>
</div>
<div class="comment_publish"><input class="submit" type="submit" value="评论"></div>
</div>
</div>
<div class="comment_bar"><a href="javascript:void(0)" class="comment_click"></a></div>
</div>
如果想从submit处定位,获取到comment处DIv的ID,那么就可以这样做:
ID值为:
[javascript] view plaincopy
$("submit")parent()parent()parent()parent()attr('id');
其值为:22;
CLASS值为:
[javascript] view plaincopy
$("submit")parent()parent()parent()parent()attr('class')
其值为:comment;
(1)如果使用javascript *** 作,可以使用孩子节点方法,如下:
documentgetElementById("tableDiv")firstChild即可以获得该table元素;
(2)如果使用jquery库,则可以使用CSS选择器按标签来选择,如下:
$("#tableDiv table")
为table定义一个 类或者id 反正就是能找到他就行
然后
$('table')find('td')each(function(i){if($(this)html()=="")
{
alert('第'i'个TD为空');
}
});
var boxTop = $("tbody")find("tr")eq(0)offset()top; //第一行距离顶部的距离
var currentRowTop = $("tbody")find("tr")eq(10)offset()top; //指定行到顶部的距离
$("dataTables_scrollBody")scrollTop(currentRowTop - boxTop); //滚动到指定行位置
<div id="a" style="width:500px;height:400px; display:block; background-color:#eee;margin:50px auto;"></div>
//引入jQuery
<script>
var a=$("#a");
var boxX=aoffset()left;
var boxY=aoffset()top;
amousemove(function(e){
var x = epageX;
var y = epageY;
var zX=x-boxX;
var zY=y-boxY;
$(this)text("X:"+zX+"Y:"+zY);
});
</script>
以上就是关于js或jquery定位光标全部的内容,包括:js或jquery定位光标、如何用Jquery获取某一个Div的Class或者ID、用jquery定位div下的table等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)