admin管理员组文章数量:1023764
I am trying out this rather simple code. It is supposed to shift the focus to the neighboring text input whenever there is mouseup
on the first one:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$(".foo").mouseup(function() {
$(".boo").focus();
});
});
</script>
</head>
<body>
<input type='text' class='foo' />
<input type='text' class='boo' />
</body>
</html>
In all browsers except IE9
(I didn't dare test it in IE8
or below!), it works fine for both left button and right button (for right button mouseup
, the context menu still pops up on the first input even though the focus shifts to the 2nd one). However, in IE9
, the focus still remains on the first text input (the context menu also popping up there).
Is there any way to fix it so that the focus shifts to the 2nd one?
I am trying out this rather simple code. It is supposed to shift the focus to the neighboring text input whenever there is mouseup
on the first one:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis./ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$(".foo").mouseup(function() {
$(".boo").focus();
});
});
</script>
</head>
<body>
<input type='text' class='foo' />
<input type='text' class='boo' />
</body>
</html>
In all browsers except IE9
(I didn't dare test it in IE8
or below!), it works fine for both left button and right button (for right button mouseup
, the context menu still pops up on the first input even though the focus shifts to the 2nd one). However, in IE9
, the focus still remains on the first text input (the context menu also popping up there).
Is there any way to fix it so that the focus shifts to the 2nd one?
Share Improve this question edited Jul 1, 2016 at 16:03 NedStarkOfWinterfell asked Feb 24, 2013 at 22:16 NedStarkOfWinterfellNedStarkOfWinterfell 5,24328 gold badges112 silver badges204 bronze badges 3- Can you try doing this in pure JS just to see if it works? So document.getElementById(element).focus(); – karancan Commented Feb 24, 2013 at 22:28
- Lemme try. Give me two minutes... – NedStarkOfWinterfell Commented Feb 24, 2013 at 22:29
- Nope. It doesn't work, as expected..:( – NedStarkOfWinterfell Commented Feb 24, 2013 at 22:30
2 Answers
Reset to default 3.select() in ie should work:
http://jsfiddle/n4hGC/5/
$(document).ready(function(){
$('.foo').mouseup(function() {
$('.boo').focus();
});
$('.foo').contextmenu(function() {
$('.boo').select();
return false;
});
});
Have also handled the context menu by returning false. Hope helps!
Can you try one of these alternatives? They have worked for me in IE8 in the past and they might work for you.
Alternative 1: Blur then Focus
$(".foo").mouseup(function(){
$(".boo").blur();
$(".boo").focus();
});
Alternative 2: Using setTimeout
$(".foo").mouseup(function(){
setTimeout(function () {
$(".boo").focus();
}, 100);
});
I am trying out this rather simple code. It is supposed to shift the focus to the neighboring text input whenever there is mouseup
on the first one:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$(".foo").mouseup(function() {
$(".boo").focus();
});
});
</script>
</head>
<body>
<input type='text' class='foo' />
<input type='text' class='boo' />
</body>
</html>
In all browsers except IE9
(I didn't dare test it in IE8
or below!), it works fine for both left button and right button (for right button mouseup
, the context menu still pops up on the first input even though the focus shifts to the 2nd one). However, in IE9
, the focus still remains on the first text input (the context menu also popping up there).
Is there any way to fix it so that the focus shifts to the 2nd one?
I am trying out this rather simple code. It is supposed to shift the focus to the neighboring text input whenever there is mouseup
on the first one:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis./ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$(".foo").mouseup(function() {
$(".boo").focus();
});
});
</script>
</head>
<body>
<input type='text' class='foo' />
<input type='text' class='boo' />
</body>
</html>
In all browsers except IE9
(I didn't dare test it in IE8
or below!), it works fine for both left button and right button (for right button mouseup
, the context menu still pops up on the first input even though the focus shifts to the 2nd one). However, in IE9
, the focus still remains on the first text input (the context menu also popping up there).
Is there any way to fix it so that the focus shifts to the 2nd one?
Share Improve this question edited Jul 1, 2016 at 16:03 NedStarkOfWinterfell asked Feb 24, 2013 at 22:16 NedStarkOfWinterfellNedStarkOfWinterfell 5,24328 gold badges112 silver badges204 bronze badges 3- Can you try doing this in pure JS just to see if it works? So document.getElementById(element).focus(); – karancan Commented Feb 24, 2013 at 22:28
- Lemme try. Give me two minutes... – NedStarkOfWinterfell Commented Feb 24, 2013 at 22:29
- Nope. It doesn't work, as expected..:( – NedStarkOfWinterfell Commented Feb 24, 2013 at 22:30
2 Answers
Reset to default 3.select() in ie should work:
http://jsfiddle/n4hGC/5/
$(document).ready(function(){
$('.foo').mouseup(function() {
$('.boo').focus();
});
$('.foo').contextmenu(function() {
$('.boo').select();
return false;
});
});
Have also handled the context menu by returning false. Hope helps!
Can you try one of these alternatives? They have worked for me in IE8 in the past and they might work for you.
Alternative 1: Blur then Focus
$(".foo").mouseup(function(){
$(".boo").blur();
$(".boo").focus();
});
Alternative 2: Using setTimeout
$(".foo").mouseup(function(){
setTimeout(function () {
$(".boo").focus();
}, 100);
});
本文标签: javascriptText Input focus anomaly in IE9Stack Overflow
版权声明:本文标题:javascript - Text Input focus anomaly in IE9 - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745510770a2153815.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论