代码之家  ›  专栏  ›  技术社区  ›  Jamie Taylor

jquery更改功能不工作

  •  6
  • Jamie Taylor  · 技术社区  · 15 年前

    我好像做不到这个工作,好像应该这样

    $('.titleother').change(function() {
    
    if ($('.titleother').val() == 'Other') {
        ​$('.hiddentext').css('display','block')
    }​​​
    
    })
    

    对于此HTML

    <select class="titleother">​
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="Other">Other</option>
    </select>
    
    <p class="hiddentext" style="display:none">TEXT</p>
    

    有什么想法吗?

    3 回复  |  直到 11 年前
        1
  •  13
  •   Marwelln    15 年前

    使用Chrome对我很有用:

    $(function(ready){
        $('.titleother').change(function() {
            if ($(this).val() == 'Other') {
                $('.hiddentext').show();   
            }
        });
    });
    

    http://jsfiddle.net/amuec/11/

    (达林的密码也不适合我)

        2
  •  5
  •   Darin Dimitrov    15 年前

    一定要把这个放在 $(document).ready 以便在附加 .change() 处理程序:

    $(function() {
        $('.titleother').change(function() {
            if ($(this).val() == 'Other') {
                ​$('.hiddentext').show();
            }​​​
        });
    });
    
        3
  •  4
  •   svk    15 年前

    我想你不见了 ;
    Check here