简体   繁体   English

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

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

I am working on product filters where user select from the select box according to his/her preference but I am not getting selected value by user in jQuery.我正在研究产品过滤器,用户根据他/她的喜好从选择框中选择,但我没有在 jQuery 中获得用户选择的值。

html code: 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 code: 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);
        });
    });

Hi I believe that your code is perfect.嗨,我相信您的代码是完美的。 Once please check jquery.min.js is included in your file.一次请检查 jquery.min.js 是否包含在您的文件中。 Please check if there are any console errors.Thank you.请检查是否有任何控制台错误。谢谢。

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

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