<!doctype html>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<li>
<div class="vt-el-inner">
<div class="inner-logo">
<img src="/PPIMG/001jpg">
</div>
<div class="inner-title"><span>1</span>马格全屋定制</div>
<div class="inner-btn">
<div class="vote-count fl">7899票</div>
<button class="vote-send fr" onclick="asd(this)">投TA一票</button>
</div>
</div>
</li>
<li>
<div class="vt-el-inner">
<div class="inner-logo">
<img src="/PPIMG/002jpg">
</div>
<div class="inner-title"><span>2</span>马格全屋定制</div>
<div class="inner-btn">
<div class="vote-count fl">789票</div>
<button class="vote-send fr" onclick="asd(this)">投ta一票</button>
</div>
</div>
</li>
<script type="text/javascript" src="jquery-321js"></script>
<script type="text/javascript">
function asd(obj){
var ret = $(obj)parent()siblings("inner-title")find("span")html();
consolelog(ret)
}
</script>
</body>
</html>
需要引入jquery
<td onmousedown="doit(this)">9:00-12:00</td>
function doit(e)
{
var tr = eparentNode;
var i = 0;
while(trpreviousSibling) i++;
alert("行号:"+i+"; 值:"+einnerHTML);
}
function test(){
var tab = documentgetElementById('tab');
var len = tabgetElementsByTagName('tr')length;
var rownum = len<10objNamesubstring(objNamelength-1):objNamesubstring(objNamelength-2);
}
其实如果你只是想要获取当前行号的话,没必要从id截取字符串,这样写:
<script language="javascript">
windowonload=function(){
var tab = documentgetElementById('tab');
var objs = tabgetElementsByTagName('input');
for(var i=0;i<objslength;i++){
objs[i]onclick=function(){
var rownum = thisparentNodeparentNoderowIndex+1;
alert("我所在的行号为:"+rownum);
}
}
}
</script>
<table border="1" id="tab" width="37%">
<tr>
<td width="68"><input type="text" value="点击我获取行号" /></td>
<td>x4</td>
</tr>
<tr>
<td width="68"><input type="text" value="点击我获取行号" /></td>
<td>14</td>
</tr>
<tr>
<td width="68"><input type="text" value="点击我获取行号" /></td>
<td>24</td>
</tr>
<tr>
<td width="68"><input type="text" value="点击我获取行号" /></td>
<td>34</td>
</tr>
<tr>
<td width="68"><input type="text" value="点击我获取行号" /></td>
<td>44</td>
</tr>
</table>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" ">
以上就是关于js怎么获取当前点击的div里面 span里面的值全部的内容,包括:js怎么获取当前点击的div里面 span里面的值、JS实现:table点击鼠标如何获取行号跟该单元的值、js如何取行号等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)