jQuery 更改功能不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4012996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery change function not working
提问by Jamie Taylor
I can't seem to get this working seems like it should
我似乎无法正常工作
$('.titleother').change(function() {
if ($('.titleother').val() == 'Other') {
?$('.hiddentext').css('display','block')
}???
})
For this HTML
对于这个 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>
Any ideas?
有任何想法吗?
回答by Marwelln
This works for me using Chrome:
这对我使用 Chrome 有效:
$(function(ready){
$('.titleother').change(function() {
if ($(this).val() == 'Other') {
$('.hiddentext').show();
}
});
});
(Darin's code didn't work for me either)
(达林的代码也不适合我)
回答by Darin Dimitrov
Make sure you put this in a $(document).ready
so that the DOM is ready when you attach the .change()
handler:
确保将其放在 a 中,$(document).ready
以便在附加.change()
处理程序时 DOM 已准备就绪:
$(function() {
$('.titleother').change(function() {
if ($(this).val() == 'Other') {
?$('.hiddentext').show();
}???
});
});
回答by svk
I think you are missing ;
Check here
我想你错过了;
检查这里