Home > Web Front-end > JS Tutorial > body text

JavaScript(js)设置默认输入焦点(focus)_javascript技巧

WBOY
Release: 2016-05-16 17:45:04
Original
986 people have browsed it

常常会在回复和引用里使用此功能,即单击回复或引用,如让输入焦点出现在留言输入框中,如果使用锚来定位,输入焦点就不能激活了。

复制代码 代码如下:

javascript:document.getElementById("id").focus();
或javascript:document.all.id.focus();
或javascript:document.all.name.focus();

例子
复制代码 代码如下:




进一步来看看本博客所使用的回复和引用的定位,及焦点如何定位在文字的右边。
复制代码 代码如下:

//引用调用函数
function quote(name,id){
var quoteMsg=document.getElementById(id).innerHTML;
var content=document.getElementById("comment");
quoteMsg=quoteMsg.replace(/JavaScript(js)设置默认输入焦点(focus)_javascript技巧/g, "~^").replace(/
/g,'n');
content.focus();//要让焦点在文字的右边,这行代码要在前面
content.value=quoteMsg+'【引用 ‘+name+'】'+'n'+'——————————————————————'+'n'; //后填入文字
return false; //取消href的作用
}
//回复自动输入姓名函数
function backcomment(msg){
backdb=document.getElementById(‘comment');
backdb.focus();
backdb.value=msg+'n';
return false;
//return true; 原来用锚来定位
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!