dong8010 2004-09-20 11:21:27
<iframe>是可编辑状态,如何得到光标所在的位置(谢谢!!);
...全文
331 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
onlytiancai 2004-09-21
  • 打赏
  • 举报
回复
挺好,挺实用的
whnnet 2004-09-21
  • 打赏
  • 举报
回复
<iframe id=x name=x></iframe>
<input type=button onclick=t() value=test>
<script>
setTimeout('window.frames["x"].document.designMode="On"',200)
function t()
{
window.frames["x"].focus()
o=window.frames["x"].document.selection.createRange()
o.pasteHTML("<b style='color:red'>"+document.all.xx.value+"</b>")
}
</script>
输入:<input id=xx>
whnnet 2004-09-21
  • 打赏
  • 举报
回复
用selection.createRange()

http://lucky.myrice.com/javascriptexam/inserttextarea.htm
soonquick 2004-09-21
  • 打赏
  • 举报
回复
<input type="text" value="0" id="pnum" size="8">
-----------------------------------------------------
var rng = event.srcElement.createTextRange();

rng.moveToPoint(event.x,event.y);
rng.moveStart("character",-event.srcElement.value.length);

pnum.value = rng.text.length;//rng.text.length就是光标位置
flyskytoday 2004-09-20
  • 打赏
  • 举报
回复
不明白<iframe>是可编辑状态

这是获取光标

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>获取鼠标坐标</title>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
<Script>
function getCoordinate(evnt)
{
if (document.all) {
x = event.screenX;
y = event.screenY;
m = window.event.x;
n = window.event.y;
}
else {
x = evnt.screenX;
y = evnt.screenX;
m = window.event.x;
n = window.event.y;
}
status = "屏幕水平坐标:"+ x + ";屏幕垂直坐标:"+ y + " 相对网页水平坐标:" + m + "相对网页垂直坐标:" + n;
}

document.onmousemove = getCoordinate;

</Script>
</form>
</body>
</html>

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧