首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >jQuery选择更改/点击问题 - 更改在IE中不起作用,点击在Chrome中不起作用?

jQuery选择更改/点击问题 - 更改在IE中不起作用,点击在Chrome中不起作用?
EN

Stack Overflow用户
提问于 2018-07-02 00:08:55
回答 2查看 0关注 0票数 0

这是我的代码:

代码语言:javascript
复制
//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如下:

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2018-07-02 09:00:58

尝试使用$ .bind()或$ .change()来代替。我之前没有遇到过这个问题。

代码语言:javascript
复制
$('.select_change').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;
        });
票数 0
EN

Stack Overflow用户

发布于 2018-07-02 10:08:18

你可以在两种情况下都可以这样做:

代码语言:javascript
复制
$('.select_change').live("change click", function(){
   $(this).parent().find(".hidden").toggle($(this).val() == 'other');
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100000367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档