onFocus无法在Chrome、Firefox、Safari中工作
onFocus not working in Chrome, Firefox, Safari
我有个问题。。。我在onFocus事件下调用一个函数,而该函数在onFocusevent下不能正常工作,但当我将该函数放在onMouseOver下时,它工作得很好。。。。为什么不在onFocus事件下运行函数??
html代码如下::
<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;
}
}
因为您误解了聚焦意味着什么。它与onmouse-over不同。
<a href="#" onfocus="myFunction(this)">onfocus</a>
<br>
<br>
<a href="#" onmouseover="myFunction(this)">onmouseover</a>
和js代码
function myFunction(x)
{
alert("This is "+x.text);
document.getElementById("a2").focus();
}
这是工作[JSfiddle DEMO][1]。了解区别。
相关文章:
- onbeforeunload和asp:Safari和FireFox中的更新面板
- 在Firefox上使用聚合物的javascript依赖关系的HTML导入困难;Safari
- 元素意外地隐藏在Safari的某些实例中,总是出现在Firefox、Chrome中
- JS适用于Firefox和Safari,但不适用于Chrome.此处'是我的网站
- 有没有一种方法可以在过滤掉iOS Chrome、Firefox和其他浏览器的同时检测iOS safari
- 异步加载的SVG过滤器feColorMatrix在Chrome中工作,而不是在Safari或Firefox中
- JavaScript函数在Safari中有效,但在Firefox中找不到
- Chrome,Safari在从本地存储读取时挂起,而Firefox很好
- 支持 JavaScript 的检查例程适用于 Chrome/Opera/IE,但不适用于 Firefox/Safari
- RGB 到 HEX JavaScript 函数在 Chrome 中工作,但不能在 Firefox 或 Safari 中工
- window.onbeforeunload在IE8中不触发(在Firefox,Chrome和Safari中工作正常)
- window.dispatchEvent 在 Firefox、Safari 或 IE 中不起作用
- 是否可以在FireFox/Safari中创建多个WebSocket
- AngularJS日期过滤器firefox/safari问题
- 将SVG元素导出为SVG,PNG适用于chrome,但不适用于firefox/safari
- jsPDF不工作在Chrome,只有Firefox 'Safari
- 编码浏览器扩展,插件,Firefox, Safari, Chrome等…这是可能的吗?
- 简单的javascript jQuery代码在Chrome中工作,而不是Firefox, Safari, IE
- 使用firefox/safari/IE获取drop输入
- AngularJS ng-model在Firefox/Safari/Chrome中