繁体   English   中英

jQuery在某些Mobile / IE浏览器上选择更改

[英]jQuery select change on some Mobile/IE browsers

我正在尝试实现两个不同选择框之间的依赖关系。 使用以下jQuery代码时,大多数普通浏览器都可以完美运行(Chrome / FF),但IE / Edge /某些移动浏览器不会受到该代码的影响。

    jQuery(document).ready(function($){
        $("#selectbox-dependency").change(function() {

           if ($(this).val() == "Banana") {     //value of selectbox #1
                $(".yellow").show();   //classes for each of the options in selectbox #2
                $(".red").hide();
                $(".black").hide();
                $(".gold").hide();
            }else if ($(this).val() == "cherry"){
                $(".yellow").hide();
                $(".red").show();
                $(".black").hide();
                $(".gold").hide();
            } 

        });
    }); 

谢谢!

移动设备上的val()可能是一个问题。 看看这个答案是否能使您排序:

http://stackoverflow.com/questions/4709093/jquery-mobile-val-not-working

核心问题是隐藏(.hide())选项对IE和许多移动浏览器不起作用。 我最终使用了这种自定义:(并非100%最佳,但足够好,并且可以在所有浏览器上使用)

jQuery(document).ready(function($){
    $("#selectbox-dependency").change(function() {

       if ($(this).val() == "Banana") {     //value of selectbox #1
            $(".yellow").prop('disabled', false);   //classes for each of the options in selectbox #2
            $(".red").prop('disabled', true);
            $(".black").prop('disabled', true);
            $(".gold").prop('disabled', true);
        }else if ($(this).val() == "cherry"){
            $(".yellow").prop('disabled', true);
            $(".red").prop('disabled', false);
            $(".black").prop('disabled', true);
            $(".gold").prop('disabled', true);
        } 

    });
}); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM