Javascript onFocus不适用于Chrome、Firefox和Safari
我有个问题。。。我正在onFocus事件下调用一个函数,而该函数在onFocus事件下无法正常工作,但当我将该函数放在onMouseOver下时,它工作得非常完美。。。。为什么不在onFocus事件下运行函数 html代码如下所示:Javascript onFocus不适用于Chrome、Firefox和Safari,javascript,Javascript,我有个问题。。。我正在onFocus事件下调用一个函数,而该函数在onFocus事件下无法正常工作,但当我将该函数放在onMouseOver下时,它工作得非常完美。。。。为什么不在onFocus事件下运行函数 html代码如下所示: <a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','./Images/Search1.gif',1);" onfocus="commonSear
<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','./Images/Search1.gif',1);" onfocus="commonSearchValidation('company','companyname','branchcode','isactive'); chkSpecial('company'); chkSpecial('branchcode');" onclick="clickSearch('company','branchcode','companyNameOpr','companyname','isactive');" >
<img src="Images/Search.gif" alt="Search" name="Image4" width="73" height="21" border="0" id="Image4" /></a>
我调用的函数如下所示:
function commonSearchValidation()
{
var counter=arguments.length;
var resflag = false;
for(var i=0 ; i < counter ; i++)
{
var fvalue = document.getElementById(arguments[i]).value;
if(fvalue.trim().length!=0)
{
resflag = true;
}
}
if(resflag)
{
return resflag;
}
else
{
alert(Enteronefield);
document.getElementById(arguments[0]).focus();
return resflag;
}
}
函数commonSearchValidation()
{
var计数器=arguments.length;
var resflag=false;
对于(变量i=0;i
因为你误解了聚焦的含义。它和我们的房子不一样
<a href="#" onfocus="myFunction(this)">onfocus</a>
<br>
<br>
<a href="#" onmouseover="myFunction(this)">onmouseover</a>
这是工作表。了解差异。使用firebug,按f12键,然后切换console选项卡,您将得到答案我在firebug中看到,我在jquery1.2.6.js中遇到了意外错误。。。。在这条线上。。if(name==“selected”&&jQuery.browser.safari)elem.parentNode.selectedIndex;您正在传递参数。但是在你的函数定义中没有这样的迹象。它动态地接受了所有的参数,对于IE*…
a
元素来说,如果不在a
中添加tabindex
,它就无法接收焦点(在任何浏览器中)。现在我在前面的评论中得到了答案。。。通过使用tabindex,它将在焦点上工作…是的,这就是我的意思。检查演示小提琴
function myFunction(x)
{
alert("This is "+x.text);
document.getElementById("a2").focus();
}