Instead of onfocus rather
use onfocusin,
that'll make your code to work.
EDIT
I just realized, that there is no focusin in
Firefox. Hence you need something heavier.
The script:
function changeValueOnFocus (e, elm) {
elm = elm || this;
elm.value = 1234;
return;
}
window.onload = function () {
if (window.onfocusin === undefined) {
document.getElementById('someinput').addEventListener('focus', changeValueOnFocus, false);
}
return;
}
and for input you'll
need an id:
<input id="someinput" maxlength="5" onfocusin="changeValueOnFocus(event, this);" type="text" />
Now this supposed to be a cross-browser solution.
本文讨论了Firefox浏览器中对于DOM特性如innerText、outerText、outerHTML、onfocusin、onfocusout及document.all的支持问题,并提供了替代方案。
1318

被折叠的 条评论
为什么被折叠?



