textarea focus以后没有光标?

derek3xwh 2012-04-05 09:16:14
function reply()
{


document.send.content.focus();


}
<form name="send" method="post" action="">
<div style="margin-left:10px; " >
<textarea name="content" value="cool">asasdasdasd</textarea>

</div>
</form>
<a href="#" onClick="reply(<)">回复</a>



我是想点一个回复然后光标跳到textarea中 现在是可以聚焦到textarea 但是textarea里没有闪动的光标
...全文
1314 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
bdyaicxy 2014-10-11
  • 打赏
  • 举报
回复
使用 setSelectionRange可以把光标定位到textearea上。
licip 2012-04-05
  • 打赏
  • 举报
回复
可能是:fckeditor中的代码和你写的有冲突了。要看看源代码,才好改哟。
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

整个贴出来

我们帮你找错。
[/Quote]
同上
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

HTML code

<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<textarea id="a">12……
[/Quote]



哥们 我用了fckeditor 好像是fckeditor的问题 去掉fckeditor就有光标了 有办法解决?
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

整个贴出来

我们帮你找错。
[/Quote]



<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="org.xwh.vo.blog" %>
<%@ page import="org.xwh.vo.BComment" %>
<%@ page import=" java.util.List" %>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.Iterator" %>
<html>
<head>
<script type="text/javascript" src="/Social/fckeditor/fckeditor.js"></script>
<link href="/Social/blog/style.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css">
.STYLE1 {
display:inline-block;
border-width:thin;
border-color:#000000;
border-style:groove;
}

</style>
<script type="text/javascript">
function reply(BCommentId)
{
var bcid=BCommentId;
var url="/servlet/reply?pid="+bcid;
document.send.content.focus();


}

</script>
<script type="text/javascript">


window.onload = function()
{
var oFCKeditor = new FCKeditor( 'content' ) ;
oFCKeditor.BasePath = "/Social/fckeditor/" ;
oFCKeditor.Height=100;
oFCKeditor.Width=575;
oFCKeditor.ToolbarSet='Basic';
oFCKeditor.ReplaceTextarea() ;

}
</script>
</head>
<body>
<% blog b=null;
b=(blog)request.getAttribute("blog");
int BlogId=b.getId();
List<BComment> bc=(ArrayList<BComment>)(request.getAttribute("BComments"));
int GuestId=Integer.parseInt(request.getParameter("GuestId"));
%>
<div id="page-bgbtm">
<div id="content" style="margin-left:85px; border-color:#000000;border-style:groove; border-width:thin;">

<div class="post">
<div style="background-color:#AAAAAA;">    <h2 class="title"><%=b.getTitle()%></h2></div>
<div class="entry" style="margin-left:5px; margin-right:5px;">
<%=b.getContent()%>

</div>
</div>
<div style="clear: both;">   留言内容:</div>
<form name="send" method="post" action="">
<div style="margin-left:10px; " >
<textarea name="content" value="cool">asasdasdasd</textarea>
<input type="submit" value="提交!"></input>
</div>
</form>
<div style="clear: both;">   </div>
<%if(bc!=null)
{
int CommentCount=0;
Iterator ite=bc.iterator();
while(ite.hasNext())
{
BComment bcs=(BComment)ite.next();
String src="/Social/blog/heads/"+bcs.getPicture();
CommentCount++;
int Pid=bcs.getPid();
int AuthorId=b.getUid();
boolean flag=false;
if(GuestId==bcs.getUserId()||GuestId==AuthorId)
{
flag=true;
}
%>
<div><!-- 留言层 -->
<div class="STYLE1"style="margin-left:10px;margin-right:10px;" >
<div style="border-style:groove; border-width:1px; "><%=CommentCount %>楼 作者:<%=bcs.getUserName() %> |  发表于<%=bcs.getTime() %> | <a href="#" onClick="reply(<%=bcs.getCommentId() %>)">回复</a>
<%if(flag) {%>
 | 删除
<%}%>
</div>
<div style="margin-top:10px;">
<div style="float:left;">
<img src=<%=src %> width="50px" height="50px"></div>

<div style="float:left; margin-left:10px;">
<font color=black><%=bcs.getContent() %></font>
<%if(Pid!=0){ %>
<div style="border-style:groove; border-width:thin; background-color:#DDDDDD;margin-right:10px; margin-top:10px;">
<div><font color=black><%=bcs.getPUserName()%>: </font></div>

<div><font color=black><%=bcs.getPContent() %></font></div>
</div>
<%} %>

</div>
</div>
</div>
<div style="clear: both;"> </div>

</div> <!-- 留言层 -->

<%}
int CurrentPage=Integer.parseInt(request.getParameter("CurrentPage")) ;//接受当前页面数
//System.out.println((int)request.getAttribute("count"));
int TotalPage=Integer.parseInt(String.valueOf(request.getAttribute("TotalPage")));//获得页面总数
String next=""+(CurrentPage+1);//设置下一页
if(CurrentPage>=TotalPage)//如果当前页大于总页数
{
CurrentPage=TotalPage; //当前页数设为页面总数
next=""+TotalPage;//下一页也设为总数
}

String previous=""+(CurrentPage-1); //上一页数
if(CurrentPage==1)//如果前页数为一
{
previous=""+CurrentPage;//上一页设为1

} %>

<div class="nextPage" style="margin-left:85px;"><a href="http://localhost:8080/Social/servlet/ShowBlog?id=<%=request.getParameter("id")%>¤tPage=<%=previous%>">上一页</a> |第<%=CurrentPage %>页/共<%=TotalPage %>页|
<a href="http://localhost:8080/Social/servlet/ShowBlog?id=<%=request.getParameter("id")%>¤tPage=<%=next%>">下一页</a></div>
<% }%>
</div>
</div>
<!-- end #content -->
<div id="sidebar" style="margin-right:85px;border-color:#000000;border-style:groove; border-width:thin;">
<ul>

<li>
<div id="search"> <h2>Profile</h2> </div>
<div style="margin-left:30px; width:215px;border-style:groove; border-width:thin;">
<table>
<tr>
<td align="center">
<img src="/Social/blog/heads/<%=b.getPicture() %>" >
</td>
</tr>
</table>
</div>
</li>
<li>
<h2><%=b.getAuthor() %></h2>
<ul>
<li>Email:<%=b.getEmail() %></li>
<li>School:<%=b.getSchool() %></li>
<li>BlogCategory:<%=b.getCategory()%></li>
<li>PostDate:<%=b.getTime() %></li>

</ul>
</li>
<li>
</ul>
</div>
<!-- end #sidebar -->
</div>
</body>
</html>
</html>
还在加载中灬 2012-04-05
  • 打赏
  • 举报
回复
整个贴出来

我们帮你找错。
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

HTML code

<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<textarea id="a">12……
[/Quote]



你的我也有光标....为什么我的代码不行
001007009 2012-04-05
  • 打赏
  • 举报
回复

<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<textarea id="a">123</textarea>
<button id="btn">click</button>
<script>
function $(el){
return typeof el == 'string' ? document.getElementById(el) : el;
}
$('btn').onclick = function(){
$('a').focus();
}
</script>
</body>
</html>



没问题啊。有光标的。
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

楼主 什么 浏览器?
[/Quote]
我用chrome也一样
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

楼主 什么 浏览器?
[/Quote]
ie 6
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
我自己写的是这样<a href="#" onClick="reply()">回复</a>
发帖时候打错了
001007009 2012-04-05
  • 打赏
  • 举报
回复
楼主 什么 浏览器?
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

<a href="#" onClick="reply()">回复</a>
[/Quote]

同上
derek3xwh 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

<a href="#" onClick="reply(<)">回复</a>
这个地方应该有错

改成
<a href="#" onClick="reply()">回复</a>试下
[/Quote]


不好意思 我打错了 我自己的代码这个位置没错 也可调js 点击以后如果页面看不到textarea 是可以跳到textarea 但就没有光标
001007009 2012-04-05
  • 打赏
  • 举报
回复
<a href="#" onClick="reply()">回复</a>
还在加载中灬 2012-04-05
  • 打赏
  • 举报
回复
<a href="#" onClick="reply(<)">回复</a>
这个地方应该有错

改成
<a href="#" onClick="reply()">回复</a>试下

87,992

社区成员

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

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