繁体   English   中英

在选择下拉选项上显示div

[英]Show div on select dropdown option

当用户从下拉菜单中选择一个选项时,我想显示一个div。 它可以在localhost上和Codepen上工作,但是当我将代码上传到域服务器时,它不起作用。

我正在为这个问题而苦苦挣扎,不知道为什么这行不通。

代码很长,这就是为什么我没有在这里分享它。

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

$(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();
    });

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

原因是:我猜您的网站上没有包含jQuery脚本。 将此代码添加到页面标签中。

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

但是,请查看我在服务器上托管的此实时页面,以向您展示演示。

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

暂无
暂无

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

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