Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多个复选框';s和Jquery_Jquery_Css_Checkbox - Fatal编程技术网

多个复选框';s和Jquery

多个复选框';s和Jquery,jquery,css,checkbox,Jquery,Css,Checkbox,我有多个复选框(26)。其ID为“复选框1”、“复选框2”等 如何使这些复选框在代码$(“#复选框XXX”).prop('checked',true)中工作所以脚本(或css)将根据链接地址自动添加为#复选框-1或#复选框-2? 代码如下: 这里还有一张所需的图片 好的,让我们看看这是否有帮助 首先保存与窗口相关的所有复选框的位置: var i = 0, lb = $('label[for*=check-box]'), ck = $('input[type=checkbox]')

我有多个复选框(26)。其ID为“复选框1”、“复选框2”等

如何使这些复选框在代码
$(“#复选框XXX”).prop('checked',true)中工作所以脚本(或css)将根据链接地址自动添加为#复选框-1或#复选框-2?
代码如下:

这里还有一张所需的图片

好的,让我们看看这是否有帮助

首先保存与窗口相关的所有复选框的位置:

var i = 0,
    lb = $('label[for*=check-box]'),
    ck = $('input[type=checkbox]'),
    len = lb.length,
    lbPos = definePositions();

function definePositions(){
    var i = 0,
        pos = [];
    // save the positions of the labels into an array
    for(;i<len;i++){ // iterate through the array with all of the checkboxes in order to save their position
        pos[i] = lb.eq(i).offset().top; // this gives you the current position of the label
    }
    return pos;
}
var i=0,
lb=$('label[for*=复选框]),
ck=$('input[type=checkbox]'),
len=磅长,
lbPos=定义位置();
函数定义位置(){
var i=0,
pos=[];
//将标签的位置保存到数组中

对于(;I您需要更好地解释这个问题。您的问题在css选择器中?是的,它是。我想它是关于选择器的。然后尝试输入[type=checkbox]:checkedNot it.$(“#复选框放置数字”).prop('选中',true);如何使它自动放置所需的id。例如:当链接转到此位置时,它会添加.prop('checked',true);看起来你需要的是Javascript。当用户滚动页面以自动选中复选框时,你想要它,是吗?我必须保存什么位置?不明白。如果你有时间:这是俄语的网站,但我用英语制作了手风琴选项和链接-“单击此处”。我不知道如何让它工作。就像我是个傻瓜。也许如果你能看到我想要的东西…你可以帮助我。还有CSS attr[id^=“check box-”]。有可能让smt像这样在JS或Jquery中工作吗?删除我给你的代码,让我看到没有javascript错误的网站,这样我就可以测试它;)删除。但不是整个网站都在我的建设中,所以有一个错误作为礼物*)。也做了一个链接“点击这里”,因为我希望它是。
// bind the page scroll event and check for the positions
$(window).unbind('scroll').scroll(function() {
    var s = $(window).scrollTop();
    for(i=0;i<len;i++){ // iterate through the array with all the positions of the checkboxes
        if(lbPos[i]<=s){ // if the position of the checkbox is less or equal to current scroll
            ck.eq(i).prop('checked', true); // prop the checkbox for true to open
        }else{
            ck.eq(i).prop('checked', false); // fallback to false to all other checkboxes
        }
    }
    lbPos = definePositions(); // redefine the label positions, since it changes with the accordion
});