在magento上使用fvalidate出现的input在页面加载完后获得焦点的解决办法

来源:互联网 发布:sql 代表什么 编辑:程序博客网 时间:2024/06/07 11:54

试了很多个都不太理想,开始以为是placeholder的问题,然后找错了方向。

后来发现是

Change document.activeElement programmatically in JavaScript


后来发现是由于它变成了activeElement的问题,虽然采用类似这种方法

<body onLoad="if(document.getElementById('food').value!=''){document.getElementById('food').style.backgroundImage='none';}">
<input type="text" id="food" onFocus="this.style.backgroundImage='none';" onBlur="if(!this.value){this.style.backgroundImage='url(pics/m_form_post.png)';}" name="food"/>
http://stackoverflow.com/questions/5131478/javascript-input-placeholder-text-using-background-image-onload-issue

可是输入邮箱那里的激活状态的游标还在啊,呵呵哒。

最后发现是页面加载完以后id为email的那个Input标签变成了activeElement

然后终于在茫茫的大海中找到了这个人说的

f you want to set the activeElement back to the default (the <body> element in most browsers), just call the active element'sblur() method:

document.activeElement.blur();
在<body>标签中加入了onload="document.activeElement.blur();"然后终于解决了,希望对于其他人也是有用的。

0 0
原创粉丝点击