简体   繁体   English

选择选项显示/隐藏IE9问题

[英]Select option show/hide IE9 issue

Hy, HY,

I have a long list and I decided 2 make it short by putting all the content list in a select options, and when you select a certain manufacturer it shows the phone number for that manufacturer in case. 我的清单很长,我决定2通过将所有内容清单都放在选择选项中来使其简短,当您选择某个制造商时,它会显示该制造商的电话号码,以防万一。 When I was testing it in different browsers (Chrome, Firefox, Opera, Safari), when I got to the famous Internet Explorer (ver. 9), boom is not working. 当我在不同的浏览器(Chrome,Firefox,Opera,Safari)中对其进行测试时,当我进入著名的Internet Explorer(版本9)时,景气无法正常工作。 When I select any option, it doesn't show anything at all. 当我选择任何选项时,它根本不显示任何内容。

My following html markup is: 我的以下html标记是:

<select id="technical-assit">
                <option value="choose-brand">Choose Manufacturer</option>
                <option value="3COM">3COM</option>
                <option value="3DFX">3DFX</option>
                <option value="ACER">ACER</option>
                <option value="AIRIS">AIRIS</option>
                <option value="AIT">AIT</option>
                <option value="AGFA">AGFA</option>
                <option value="AIRTEL">AIRTEL / VODAFONE</option>
                <option value="AIWA">AIWA</option>
                <option value="ALCATEL">ALCATEL</option>
</select>

<div id="3COM" class="contact-number" style="display:none">91 509 69 00</div>
<div id="3DFX" class="contact-number" style="display:none">900 501 303</div>
<div id="ACER" class="contact-number" style="display:none">902 202 323</div>
<div id="AIRIS" class="contact-number" style="display:none">902 103 444</div>
<div id="AIT" class="contact-number" style="display:none">902 11 66 21</div>
<div id="AGFA" class="contact-number" style="display:none">902 15 25 93</div>
<div id="AIRTEL" class="contact-number" style="display:none">607 123 000</div>
<div id="AIWA" class="contact-number" style="display:none">91 358 11 02</div>
<div id="ALCATEL" class="contact-number" style="display:none">91 330 40 00</div>

Is just a small part of the list. 只是列表的一小部分。 And my java script markup is : 我的Java脚本标记是:

<script>

    $(function() {
    $('#technical-assit').change(function(){
        $('.contact-number').hide();
        $('#' + $(this).val()).show();
    });
});

</script>

Any ideas ?! 有任何想法吗 ?!

Thank you 谢谢

the cause is that IE have some problem with change method you can see here and you can also see change method in documentation , it say that As of jQuery 1.4, the change event bubbles in Internet Explorer, behaving consistently with the event in other modern browsers. 原因是IE的change方法有问题,您可以在这里看到,您也可以在文档中看到change方法 ,它说从jQuery 1.4开始,Internet Explorer中的change事件冒泡,与其他现代浏览器中的事件保持一致。

to render this work you should use click method rather than change in IE, and for other browser like mozilla, chrome .... use change method. 要渲染此作品,您应该使用click方法而不是在IE中进行更改,对于其他浏览器(如mozilla,chrome ....),请使用change方法。

to do this in one step you can use change and click at the same time like this : 要一步完成此操作,您可以使用change并同时单击,如下所示:

<script>

$(function() {
   $('#technical-assit').live("change click", function(){
      $('.contact-number').hide();
      $('#' + $(this).val()).show();
   });
});

this code use .live() to responds to both events 此代码使用.live()来响应两个事件

note: if you use jQuery 1.7+ live() method is removed and you can use on() method instead 注意:如果使用jQuery 1.7+,则live()方法将被删除,而可以使用on()方法代替

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

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