Jquery 检查复选框值是否已更改(选中或未选中),然后运行函数

Jquery 检查复选框值是否已更改(选中或未选中),然后运行函数,jquery,Jquery,您好,我是jquery的新手,我想知道执行以下操作有多简单 我有许多列表项都包含动态拉取的内容,这意味着每个列表项的高度可能会有所不同。我正在运行一个jquery函数,该函数检查每个列表项的高度,然后将所有列表项设置为最高列表项的高度。这一切在$(window).resize(function()事件)上都可以正常工作,但是我正在寻找一个函数,该函数可以调整当复选框状态更改(选中或未选中)时要触发的列表项的大小。我正在努力找出如何有效地执行此操作 在此方面的任何帮助都将不胜感激 谢谢 乔恩 我使

您好,我是jquery的新手,我想知道执行以下操作有多简单

我有许多列表项都包含动态拉取的内容,这意味着每个列表项的高度可能会有所不同。我正在运行一个jquery函数,该函数检查每个列表项的高度,然后将所有列表项设置为最高列表项的高度。这一切在$(window).resize(function()事件)上都可以正常工作,但是我正在寻找一个函数,该函数可以调整当复选框状态更改(选中或未选中)时要触发的列表项的大小。我正在努力找出如何有效地执行此操作

在此方面的任何帮助都将不胜感激

谢谢 乔恩

我使用的代码如下-不是使用.change()事件,而是使用(window).resize事件。建议将不胜感激-提前感谢

var currentTallest = 0,
                currentRowStart = 0,
                rowDivs = new Array();

            function setConformingHeight(el, newHeight) {
                    // set the height to something new, but remember the original height in case things change
                    el.data("originalHeight", (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight")));
                    el.height(newHeight);
            }

            function getOriginalHeight(el) {
                    // if the height has changed, send the originalHeight
                    return (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight"));
            }

            function columnConform() {

                    // find the tallest element in the row, and set the heights of all of the elements to match it.
                    $('#results > li').each(function() {

                            // "caching"
                            var $el = $(this);

                            var topPosition = $el.position().top;

                            if (currentRowStart != topPosition) {

                                    // we just came to a new row.  Set all the heights on the completed row
                                    for(currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);

                                    // set the variables for the new row
                                    rowDivs.length = 0; // empty the array
                                    currentRowStart = topPosition;
                                    currentTallest = getOriginalHeight($el);
                                    rowDivs.push($el);

                            } else {

                                    // another div on the current row.  Add it to the list and check if it's taller
                                    rowDivs.push($el);
                                    currentTallest = (currentTallest < getOriginalHeight($el)) ? (getOriginalHeight($el)) : (currentTallest);

                            }
                            // do the last row
                            for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);

                    });

            }


           $('fieldset#filter[type="checkbox"]').change(function() { 
                    columnConform();

            });
var=0,
currentRowStart=0,
rowDivs=新数组();
功能设置符合高度(el,新高度){
//将高度设置为新的高度,但记住原始高度以防发生变化
高程数据(“原始高度”),(高程数据(“原始高度”)==未定义)?(高程()):(高程数据(“原始高度”));
标高高度(新高度);
}
函数原始高度(el){
//如果高度已更改,请发送原始高度
返回(el.data(“原始高度”)==未定义)?(el.height()):(el.data(“原始高度”));
}
函数columnConform(){
//找到行中最高的元素,并将所有元素的高度设置为与之匹配。
$('#results>li')。每个(函数(){
//“缓存”
var$el=$(本);
var topPosition=$el.position().top;
if(currentRowStart!=topPosition){
//我们刚来到一个新的一排。在完成的一排上设置所有的高度
对于(currentDiv=0;currentDiv
您可以使用jQuery的
change
事件捕获复选框上的更改

e、 g.
$('input[type=“checkbox”]”)。更改(函数(){/*此处调整逻辑大小*/});

您可以更改
输入[type=“checkbox”]
位以缩小范围


如果要选择任何类别为
myChkbox
的复选框,请使用:
$('.myChkbox')…
如果要将其应用于特定表单(id=myform)中的所有复选框,请使用:
$('form#myform input[type=“checkbox”]”)…
等。

.change()
是实现这一点的方法。但是我认为他不想在所有复选框上运行此操作;)谢谢您的帮助-我想在具有特定字段集ID的复选框上运行.change()事件。这可能吗?是的,我知道,但我认为更改选择器很简单。我会给你看@jonjones。。。我会编辑这个问题。对不起-是的,很简单。谢谢你的帮助:)别难过!:)我认为,因为您已经在使用jquery,所以您应该已经知道如何更改选择器等。:)如果托马斯以你期望的方式帮助了你,那么接受他的回答。