每个循环内的 Jquery 单击事件在 IE 中不起作用
我继承了这段代码,并试图让它工作。它生成一个选择菜单,用于过滤产品页面。最初,它生成 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是IE的问题。 IE 选择(当涉及选项时)总是有不奇怪的行为。
我在新闻组中找到了这个。
所以我认为你必须使用 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.
and so i think you have to use a javascript workaround instead of using the jquery "click" event
试试这个
Try this