简体   繁体   English

在选择下拉选项上显示div

[英]Show div on select dropdown option

I want to show a div when the user select a option out the dropdown. 当用户从下拉菜单中选择一个选项时,我想显示一个div。 It works on localhost and with codepen but when I upload the code to the server of my domain it doesn't work.. 它可以在localhost上和Codepen上工作,但是当我将代码上传到域服务器时,它不起作用。

I'm struggling with this problem and have no idea why this doesn't work. 我正在为这个问题而苦苦挣扎,不知道为什么这行不通。

The code is very long, thats why I didn't share it here. 代码很长,这就是为什么我没有在这里分享它。

HTML: HTML:

 <select>
                <option>choose a option</option>
                <option value="test1">test 1</option>
                <option value="test2">test 2</option>
            </select>

            <div class="test1 pricebox"><strong>test1 - test2</strong> <h1>€27,50</h1></div>
            <div class="test2 pricebox"><strong>test2 - test1</strong> <h1>€27,50</h1></div>

JS JS

$(document).ready(function(){
        $("select").change(function(){
        $(this).find("option:selected").each(function(){
        if($(this).attr("value")=="test1"){
            $(".pricebox").not(".test1").hide();
            $(".test1").show();
        }
        else if($(this).attr("value")=="test2"){
            $(".pricebox").not(".test2").hide();
            $(".test2").show();
        }
        else{
            $(".pricebox").hide();
        }
        });
    }).change();
    });

The codepen (it works) http://codepen.io/anon/pen/aOGvJq Codepen(有效) http://codepen.io/anon/pen/aOGvJq

The reason is : you're not including the jQuery script on your website I guess. 原因是:我猜您的网站上没有包含jQuery脚本。 Add this code in the tag of your page. 将此代码添加到页面标签中。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>

However check this live page I hosted this on server to show you demo. 但是,请查看我在服务器上托管的此实时页面,以向您展示演示。

http://shehroz.pixub.com/stack.html http://shehroz.pixub.com/stack.html

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

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