
<html>
<head>
<script>
var cell="";
function mm(str)
{
cell=str;
}
function me()
{
alert(cell);
}
</script>
</head>
<body>
<table id="t" name="t" border="2" width="300">
<tr>
<td id="1" onmousedown="mm(thisid)">111</td>
<td id="2" onmousedown="mm(thisid)">222</td>
<td id="3" onmousedown="mm(thisid)">333</td>
</tr>
<tr>
<td id="4" onmousedown="mm(thisid)">444</td>
<td id="5" onmousedown="mm(thisid)">555</td>
<td id="6" onmousedown="mm(thisid)">666</td>
</tr>
<tr>
<td id="7" onmousedown="mm(thisid)">777</td>
<td id="8" onmousedown="mm(thisid)">888</td>
<td id="9" onmousedown="mm(thisid)">999</td>
</tr>
</table><br>
<input type="button" value="fdsfsa" onclick="me()">
</body>
</html>
// textarea的id为test,修改一下
var t = documentgetElementById('test');
tonclick = function () {
var v = thisvalue;
var cv = '';
if ('selectionStart' in t) {
cv = vsubstr(0, tselectionStart);
} else {
var oSel = documentselectioncreateRange();
oSelmoveStart('character', -tvaluelength);
cv = oSeltext;
}
// 获取当前是几行
var cl = cvsplit('\n')length - 1;
// 当前行的内容
var clv = vsplit('\n')[cl];
// 获取空格数量
var spaceCount = clvreplace(/^(\s)/, '$1')length;
alert(spaceCount);
}
你应该在页面或某个控件中加mouseover事件,当鼠标进入后就触发这个事件 var event = windowevent || argumentscalleecallerarguments[0]; var x = eventclientX; var y= eventclientY;
以上就是关于有关JavaScript中获得table中某一行光标位置的问题全部的内容,包括:有关JavaScript中获得table中某一行光标位置的问题、js 获取 textarea 光标所在行的开头有多少空格、js 怎么获取光标所在textarea里的x y 坐标等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)