IE8的html选择需要两次点击才能打开下拉菜单 [英] IE8 html select needs two clicks to open dropdown

查看:148
本文介绍了IE8的html选择需要两次点击才能打开下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <!doctype html> 
< html lang =en>
< head>
< meta charset =utf-8/>
< script src =http://code.jquery.com/jquery-1.7.1.js>< / script>
< style type =text / css>
div {
background-color:silver;
border:1px纯黑色;
width:200px;
}
< / style>
< script>
$(function(){
$(#click)。dblclick(function(e){
var options =< select id ='combobox'>
for(var i = 0; i <50; i ++){
options + ='< option value =ActionScript> Value - '+ i +'< / option>';
}
$(this).html(options +< / select>));
});
});
< / script>
< / head>
< body>
< div id =click>双击我< / div>
< / body>
< / html>

双击 div ,一个 select 元素在 div 中呈现。问题出现在 select 被渲染后的IE8中,它需要两次点击来打开下拉菜单。它应该在一次点击打开。

解决方案

最后我找到了这个解决方案。我在 $(options +< / select>)中使用了jQuery appendTo 。appendTo(this); 方法,而不是 .html ,如 $(this).html(options +< / select>));


Here is my code.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="http://code.jquery.com/jquery-1.7.1.js"></script>
<style type="text/css">
div {
    background-color: silver;
    border: 1px solid black;
    width:200px;
}
</style>
<script>
    $(function() {
        $("#click").dblclick(function(e) {
            var options = "<select id='combobox'>"
            for ( var i = 0; i < 50; i++) {
                options += '<option value="ActionScript">Value - ' + i + '</option>';
            }
            $(this).html(options + "</select>");
        });
    });
</script>
</head>
<body>
    <div id="click">double click me</div>
</body>
</html>

After double clicking on div, a select element is rendered in the div. The problem is in IE8 after select is rendered, it needs two clicks to open the dropdown menu. It should be opened in a single click.

解决方案

Finally I have found this solution. I have use jQuery appendTo as in $(options + "</select>").appendTo(this); method instead of .html as in $(this).html(options + "</select>"); .

这篇关于IE8的html选择需要两次点击才能打开下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆