繁体   English   中英

为什么 jQuery 选择框更改事件不起作用?

[英]Why jQuery Select box change event is not working?

我正在研究产品过滤器,用户根据他/她的喜好从选择框中选择,但我没有在 jQuery 中获得用户选择的值。

html代码:

<select name="product_filter" id="product_filter">
        <option value="price_low_first">Price : Low to High</option>
        <option value="price_high_first">Price : High to Low</option>
        <option value="latest">Latest</option>
        <option value="popular">Most Popular</option>
</select>

jQuery代码:

$(function () {
        $("#product_filter").change(function () {
          alert("hi")
            var selectedText = $(this).find("option:selected").text();
            var selectedValue = $(this).val();
            alert("Selected Text: " + selectedText + " Value: " + selectedValue);
        });
    });

嗨,我相信您的代码是完美的。 一次请检查 jquery.min.js 是否包含在您的文件中。 请检查是否有任何控制台错误。谢谢。

暂无
暂无

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

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