select的option触发事件

<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>Document</title>
        <style type="text/css">
            .option_show {
                display: none;
            }
            
            .discount {
                width: 70px;
            }
        </style>
    </head>

    <body>
        <select class="select" name="oyhfd">
            <option value="0" selected="selected">请选择</option>
            <option class="option" value="1">足球</option>
            <option class="option" value="2">篮球</option>
            <option class="option" value="3">乒乓球</option>
            <option class="option" value="4">网球</option>
        </select>
        <span style="display:none;" class="option_show">
    <input type="text" class="discount" id="" name="" placeholder="其他球类"/>
  </span>
    </body>

    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
        $(".select").on("change", function() {
            if($("option:selected", this).val() == 4) {
                $(".option_show").show();
            } else {
                $(".discount").val("");
                $(".option_show").hide();
            }
        });
    </script>

</html>
 

猜你喜欢

转载自www.cnblogs.com/zbly/p/9969078.html