简体   繁体   English

jQuery在DropDownList / SELECT项目上激活已更改

[英]Jquery Activate on DropDownList/SELECT item changed

I have some JQuery code that filters out a list of links on the page. 我有一些JQuery代码可以过滤出页面上的链接列表。 At present the filtering is fired when a link wih a blind href is clicked. 当前,当单击带有盲href的链接时,将触发过滤。 The id of the link is taken to determine which content remains visible on the page. 链接的ID用于确定哪些内容在页面上保持可见。 EG: 例如:

<script type="text/javascript">
$(document).ready(function () {

    //when a link in the filters div is clicked...
    $('#filters a').click(function (e) {

        //prevent the default behaviour of the link
        e.preventDefault();

        //get the id of the clicked link(which is equal to classes of our content
        var filter = $(this).attr('id');

        //show all the list items(this is needed to get the hidden ones shown)
        $('#content ul li').show();

        /*using the :not attribute and the filter class in it we are selecting
        only the list items that don't have that class and hide them '*/
        $('#content ul li:not(.' + filter + ')').hide();

    });

});

I need to changed this so that, the JQuery is activated when an option is changed in a DropDownList/SELECT. 我需要对此进行更改,以便在DropDownList / SELECT中更改选项时激活JQuery。 However, I cant quite get my head around how to change this JScript to detect the selection in the DDL rather than a hyperlink. 但是,我不太了解如何更改此JScript来检测DDL中的选择,而不是超链接。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks. 谢谢。

Use the change() event 使用change()事件

$("#idOfDropDown").change(function() {
    //code here
    var filter = this.value //gets the value of the selected dropdown item.
});

This will fire each time a dropdown selection has been made. 每次选择下拉菜单时都会触发。

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

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