gpt4 book ai didi

javascript - jQuery 选择更改/单击问题 - 更改在 IE 中不起作用,单击在 Chrome 中不起作用

转载 作者:行者123 更新时间:2023-11-30 18:54:25 25 4
gpt4 key购买 nike

正如标题所说,我在绑定(bind)到下拉选择列表中的更改时遇到问题 - 似乎“更改”不适用于 IE(7 或 8),所以当我尝试替代方法并使用“点击”事件,它在 IE 中有效,但在 Chrome 中无效!我在这里遗漏了什么明显的东西吗?

这是我的代码:

//event handler for showing hidden form elements (also ensures only relevant hidden els shown)
//IE needs click event instead of change
$('.select_change').live("change", function(){
//check if value is other
if ($(this).val() == 'other')
$(this).parent().find(".hidden").show();
//if user changes select value from other then hide input
if ($(this).val() != 'other')
$(this).parent().find(".hidden").hide();
return false;
});

下拉HTML如下:

<select id="title" name="title" class="validate[required,funcCall[validateNotDefault]] select_change" >
<option value="default" selected="selected">Please choose from options</option>
<option value="yellow">Yellow</option>
<option value="black">Black</option>
<option value="chocoloate">Chocolate</option>

<option value="other">Other</option>
</select>

最佳答案

change 仍然不能在 IE 中完全正确地冒泡,不过你可以在这两种情况下都这样做:

$('.select_change').live("change click", function(){
$(this).parent().find(".hidden").toggle($(this).val() == 'other');
});

这仍然使用 .live(),只是响应这两个事件...因为你正在做的事情不会因为触发一次或两次而受到伤害,所以在这种情况下这样做很好.使用 .toggle(bool) 上面的代码稍微短了一点稍微简化您的逻辑。

关于javascript - jQuery 选择更改/单击问题 - 更改在 IE 中不起作用,单击在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2678771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com