简体   繁体   English

显示隐藏 <DIV> 基于 <SELECT>值

[英]Show/Hide <DIV> Based on <SELECT> Value

Can anyone help point out to me what's stopping this code that works perfectly fine with jsFiddle from working in my webpage ? 谁能帮我指出是什么阻止了此与jsFiddle完美配合的代码在我的网页上工作?

I have been trying to fix this for the past couple of hours, and no matter what I do, I can't seem to get it to trigger. 在过去的几个小时中,我一直在尝试解决此问题,无论我做什么,我似乎都无法触发它。 I have a feeling it's going to be something really simple and stupid that's completely gone over my head, but it's slowly ticking me off and hindering progress on other things that rely on this. 我感觉这将是一件非常简单而愚蠢的事情,完全淹没了我的头,但是它正在慢慢地勾勒我,阻碍了其他依赖此事的进展。

I appreciate any help provided, thank you. 感谢提供的任何帮助,谢谢。

$('#select-os').change( function() {
    if (this.value == "r") {
        $('.wont').show();
        $('.ready, .will').hide();
    }
    else if (this.value == "g") {
        $('.will').show();
        $('.ready, .wont').hide();
    }
});

you need a document.ready try this: 您需要一个document.ready尝试以下操作:

$(document).ready(function (){
 $('#select-os').change( function() {
    if (this.value == "r") {
        $('.wont').show();
        $('.ready, .will').hide();
    }
    else if (this.value == "g") {
        $('.will').show();
        $('.ready, .wont').hide();
    }
 });
});

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

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