每个循环内的 Jquery 单击事件在 IE 中不起作用

发布于 2024-11-26 04:40:13 字数 1622 浏览 0 评论 0原文

我继承了这段代码,并试图让它工作。它生成一个选择菜单,用于过滤产品页面。最初,它生成 UL(选项是 LI),但现在正在转换为选择列表。这些选项在所有浏览器中都完美显示,并且在除 IE(所有版本)之外的每个浏览器中单击效果都很好。在 IE 中,我可以使用下拉菜单,但是当我单击选项时没有任何反应。

我尝试更改事件以进行更改和选择,但这似乎只会破坏一切。

预先感谢您的任何帮助!

$.each(hazardClassification, function (i) {
                cleanMenuforClass = hazardClassification[i].toLowerCase().replace(/ /g, '_').replace(/&./g, '_').replace(/\,/g, '').replace('/', '').replace('.', '');


                $("<option/>", {
                    "class": cleanMenuforClass,
                    click: function (event) {
                        $("#legend-inline-search").val("");
                            $("#pipemarker-type-selection div.product-container").css('display', '');
                        var clickedInput = $(this).attr("class");
                        var clickedCheckbox = $(this);
                        if ($(this).is(":selected")) {
                                filterItems(hazardClassification[i], clickedInput, countItems, selectedItemsContainer, clickedCheckbox);

                            } else {
                                removeFilter(hazardClassification[i], clickedInput, countItems, selectedItemsContainer);
                            }

                    }
                }).appendTo("#filter-by-classification select").append('<span>' + hazardClassification[i] + '"<span>');

        });

更新:找到了一个仍然使用 jQuery 的解决方法,并且让虚拟设计师(就是我)的事情变得简单。 是否有解决方法来触发选项.IE 中的 click 事件?

I've inherited this bit of code and I'm trying to get it working. It's generating a select menu that's being used to filter a page of products. Originally, it was generating a UL (options were LIs), but it's now being converted to a select list. The options are appearing perfectly in all browsers, and the click works great in every browser except IE (all versions). In IE, I can use the drop down, but nothing happens when I click an option.

I've tried changing the event to change and select, but that only seems to break everything.

Thanks in advance for any help!

$.each(hazardClassification, function (i) {
                cleanMenuforClass = hazardClassification[i].toLowerCase().replace(/ /g, '_').replace(/&./g, '_').replace(/\,/g, '').replace('/', '').replace('.', '');


                $("<option/>", {
                    "class": cleanMenuforClass,
                    click: function (event) {
                        $("#legend-inline-search").val("");
                            $("#pipemarker-type-selection div.product-container").css('display', '');
                        var clickedInput = $(this).attr("class");
                        var clickedCheckbox = $(this);
                        if ($(this).is(":selected")) {
                                filterItems(hazardClassification[i], clickedInput, countItems, selectedItemsContainer, clickedCheckbox);

                            } else {
                                removeFilter(hazardClassification[i], clickedInput, countItems, selectedItemsContainer);
                            }

                    }
                }).appendTo("#filter-by-classification select").append('<span>' + hazardClassification[i] + '"<span>');

        });

UPDATED: found a workaround that still uses jQuery and keeps things simple for the dummy designer (that's me). Is there a workaround to trigger an option.click event in IE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哭泣的笑容 2024-12-03 04:40:13

我认为这是IE的问题。 IE 选择(当涉及选项时)总是有不奇怪的行为。

我在新闻组中找到了这个。

我们无法使用本机事件来单击 IE 中的元素。 IE
选项元素的高度和宽度始终报告为 0,因此有
无法计算点击点应该在哪里。

所以我认为你必须使用 javascript 解决方法而不是使用 jquery“click”事件

I think this is a problem with IE. IE selects (when option are involved) always have non strange behaviours.

i found this in a newsgroup.

We can't use native events to click on an element in IE. IE
always reports height and width of 0 for option elements, so there's
no way to calculate where the click point should be.

and so i think you have to use a javascript workaround instead of using the jquery "click" event

许一世地老天荒 2024-12-03 04:40:13

试试这个

$.each(hazardClassification, function (i) {
                cleanMenuforClass = hazardClassification[i].toLowerCase().replace(/ /g, '_').replace(/&./g, '_').replace(/\,/g, '').replace('/', '').replace('.', '');


                $("option", {
                    "class": cleanMenuforClass,
                    click: function (event) {
                        $("#legend-inline-search").val("");
                            $("#pipemarker-type-selection div.product-container").css('display', '');
                        var clickedInput = $(this).attr("class");
                        var clickedCheckbox = $(this);
                        if ($(this).is(":selected")) {
                                filterItems(hazardClassification[i], clickedInput, countItems, selectedItemsContainer, clickedCheckbox);

                            } else {
                                removeFilter(hazardClassification[i], clickedInput, countItems, selectedItemsContainer);
                            }

                    }
                }).appendTo("#filter-by-classification select").append('<span>' + hazardClassification[i] + '"<span>');

        });

Try this

$.each(hazardClassification, function (i) {
                cleanMenuforClass = hazardClassification[i].toLowerCase().replace(/ /g, '_').replace(/&./g, '_').replace(/\,/g, '').replace('/', '').replace('.', '');


                $("option", {
                    "class": cleanMenuforClass,
                    click: function (event) {
                        $("#legend-inline-search").val("");
                            $("#pipemarker-type-selection div.product-container").css('display', '');
                        var clickedInput = $(this).attr("class");
                        var clickedCheckbox = $(this);
                        if ($(this).is(":selected")) {
                                filterItems(hazardClassification[i], clickedInput, countItems, selectedItemsContainer, clickedCheckbox);

                            } else {
                                removeFilter(hazardClassification[i], clickedInput, countItems, selectedItemsContainer);
                            }

                    }
                }).appendTo("#filter-by-classification select").append('<span>' + hazardClassification[i] + '"<span>');

        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文