[英]Having trouble with Javascript focus()
有3个程序,Pers1,Pers2,Pers3。 Pers1和Pers2需要填写表格,Pers3会生成报告。 Pers2包括Pers1,Pers3包括Pers2。 因此,如果您得到的只是报告,Pers1和Pers2仍会显示,并且如果您不喜欢所得到的报告,则可以调整表单。 所有这些都是用ColdFusion编写的。
有Javascript可以将焦点对准所有3个程序,并且运行良好。
在Pers3中,可以单击报表的标题,并隐藏Pers1和Pers2表单。 这允许用户在不使用先前表格的情况下打印报告。 要再次显示Pers1和Pers2,请再次单击Pers3中的标题。
一切运行良好,除了单击标题返回Pers1和Pers2时,我失去了对Pers3的关注。 我已经尝试了很多东西,但是到目前为止没有成功。 用来打开和关闭Pers1和2的Javascript,包括我重新聚焦的尝试(这里有3个div必须关闭/打开):
function hider() {
var buttonrep2 = document.getElementById('shutoff');
var buttonrep1 = document.getElementById('hiderep1');
var buttontop = document.getElementById('hidereptop');
if(buttonrep2.style.display != 'none' ) {
buttonrep2.style.display = 'none';} //shut off
else {
buttonrep2.style.display = ''; }//turn on
if(buttonrep1.style.display != 'none' ) {
buttonrep1.style.display = 'none';}
else {
buttonrep1.style.display = '';}
if(buttontop.style.display != 'none' ) {
buttontop.style.display = 'none';}
else {
buttontop.style.display = ''};
thefocus('reporthead')
}//end of function hider
并重新调整焦点,在其他地方都可以正常工作:
function thefocus(id) {
document.getElementById(id).focus();
}
有谁知道我可能做错了什么,或者如何使它工作?
如果为HTML提供tabindex
属性,则可以关注非输入元素,如下所示:
<h1 tabindex="0" id="reportHead">Report Header</h1>
然后您可以使用
document.getElementById('reportHead').focus();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.