Javascript 如何使.focus()在单选按钮阵列上工作?
我正在尝试使.focus()在IE中工作,它在chrome等中工作。我的表单名为:Javascript 如何使.focus()在单选按钮阵列上工作?,javascript,asp-classic,Javascript,Asp Classic,我正在尝试使.focus()在IE中工作,它在chrome等中工作。我的表单名为: <form name="feedbackform" action="feedback.asp" target="_self" onsubmit="return validate_txt(this)" method="post" style="margin: 0;"> 正如我所说,它在chrome、firefox等浏览器中都能正常工作,但在IE 8中,我得到了nada、zip,我不知
<form name="feedbackform" action="feedback.asp" target="_self" onsubmit="return
validate_txt(this)" method="post" style="margin: 0;">
正如我所说,它在chrome、firefox等浏览器中都能正常工作,但在IE 8中,我得到了nada、zip,我不知道为什么,也找不到令人满意的答案,有没有办法解决这个问题?当页面刚加载(例如body的onload)时,你是否调用focus -在DOM完成加载之前,可能会在代码中调用它 此外,此页面对focus()行为有很好的测试:
这可能是IE不理解[0].focus()语法。您可能想尝试以下方法:
document.forms["feedbackform"].elements["fb_commentype"][0].focus();
document.forms["feedbackform"].elements["fb_commentype"].focus();
这样,“评论”单选按钮将被聚焦
快乐编码 不,当用户按下提交按钮时,它是一个检查功能,验证输入,如果缺少内容,则将焦点设置为该项目。谢谢。我感谢您的评论,我将对此进行测试,并让您知道发生了什么。
document.forms["feedbackform"].elements["fb_commentype"][0].focus();
document.forms["feedbackform"].elements["fb_commentype"][0].focus();
document.forms["feedbackform"].elements["fb_commentype"].focus();
<input type="radio" name="fb_commentype" value="Comment" />Comment
<input type="radio" name="fb_commentype" value="Complaint" />Complaint
<input type="radio" name="fb_commentype" value="Request" />Request
document.getElementsByName('fb_commentype')[0].focus();