zoukankan      html  css  js  c++  java
  • IE6 下 jQuery 操作 select的BUG

    最近在写一个页面,在出了ie6外的所有浏览器中都正常(ie7,8,9,  firefox, chrome), IE6下提示 “无法设置selected属性。未指明的错误”。

    后来发现是jquery 在 ie6 下操作 select控件有BUG.

    我程序中是这样使用的:

    $("#genre").val(0);

    改成:

    setTimeout(function(){
        $("#genre").val(0);
    },1);

    就可以了.

    原因是:

    Note that the error will only occur if you call appendChild, then ask for the select's childNodes, then set the selected property on the newly created option. If you set selected earlier, either before appendChild or after it, there's no problem. And if you omit childNodes, it works. The problem with jQuery is that its .val() function loops over childNodes looking for an option to set, and thus always triggers the bug.

    最后可以定义个函数 set_select_val来统一设置 select控件的值

    function set_select_val(sel, val)
    {
        if($.browser.msie && $.browser.version=="6.0") {
            setTimeout(function(){
                sel.val(val);
            },1);
        }else {
                sel.val(val);
        }
    }

  • 相关阅读:
    01.mp4v2应用—mp4转h264
    00.mp4v2工具的用法
    交叉编译x264和ffmpeg
    pcm2aac
    保存一下东西
    05.移植内核3.4.2
    04.移植u-boot
    03.应用程序调试
    关于 jxl 下载 excel (java)
    JXL 对excle 操作(单元格合并,列宽,格式等)
  • 原文地址:https://www.cnblogs.com/hqr9313/p/2715463.html
Copyright © 2011-2022 走看看