jQuery更改功能无法正常工作

Jam*_*lor 7 jquery onchange

我似乎无法让这种工作看起来应该如此

$('.titleother').change(function() {

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

})
Run Code Online (Sandbox Code Playgroud)

对于这个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>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Mar*_*lln 14

这适用于我使用Chrome:

$(function(ready){
    $('.titleother').change(function() {
        if ($(this).val() == 'Other') {
            $('.hiddentext').show();   
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

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

(Darin的代码对我也不起作用)


Dar*_*rov 5

确保将其放入,$(document).ready以便在附加.change()处理程序时DOM已准备就绪:

$(function() {
    $('.titleother').change(function() {
        if ($(this).val() == 'Other') {
            ?$('.hiddentext').show();
        }???
    });
});
Run Code Online (Sandbox Code Playgroud)