Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/479.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
Javascript JQuery函数,用于创建具有某些属性的表_Javascript_Jquery_Css - Fatal编程技术网

Javascript JQuery函数,用于创建具有某些属性的表

Javascript JQuery函数,用于创建具有某些属性的表,javascript,jquery,css,Javascript,Jquery,Css,$(文档).ready(函数(){ var-nr=0; $(“#拉斯潘”)。文本(nr); 元(“#t1#e1”)。在({ mouseover:function(){ $(this.css(“背景色”、“黄色”); }, mouseleave:function(){ $(this.css(“背景色”、“绿色”); }, 单击:函数(){ $(此).off('mouseleave'); 美元(“#t1#e1”).off('mouseleave'); 美元(“#t1#e2”).off('mousel

$(文档).ready(函数(){
var-nr=0;
$(“#拉斯潘”)。文本(nr);
元(“#t1#e1”)。在({
mouseover:function(){
$(this.css(“背景色”、“黄色”);
},
mouseleave:function(){
$(this.css(“背景色”、“绿色”);
},
单击:函数(){
$(此).off('mouseleave');
美元(“#t1#e1”).off('mouseleave');
美元(“#t1#e2”).off('mouseleave');
美元(“#t1#e3”).off('mouseleave');
美元(“#t1#e4”).off('mouseleave');
$(此).off('mouseover');
$(“#t1#e1”).off('mouseover');
$(“#t1#e2”).off('mouseover');
$(“#t1#e3”).off('mouseover');
$(“#t1#e5”).off('mouseover');
$(此).off('click');
$(“#t1#e4”).off('click');
$(“#t1#e2”).off('click');
$(“#t1#e3”).off('click');
$(“#t1#e5”).off('click');
nr=1;
$(“#拉斯潘”)。文本(nr);
}
});
元(“#t1#e2”)。在({
mouseover:function(){
$(this.css(“背景色”、“黄色”);
$(“#t1#e1”).css(“背景色”、“黄色”);
},
mouseleave:function(){
$(this.css(“背景色”、“绿色”);
$(“#t1#e1”).css(“背景色”、“绿色”);
},
单击:函数(){
$(此).off('mouseleave');
美元(“#t1#e1”).off('mouseleave');
美元(“#t1#e5”).off('mouseleave');
美元(“#t1#e3”).off('mouseleave');
美元(“#t1#e4”).off('mouseleave');
$(此).off('mouseover');
$(“#t1#e1”).off('mouseover');
$(“#t1#e5”).off('mouseover');
$(“#t1#e3”).off('mouseover');
$(“#t1#e4”).off('mouseover');
$(此).off('click');
$(“#t1#e4”).off('click');
$(“#t1#e1”).off('click');
$(“#t1#e3”).off('click');
$(“#t1#e5”).off('click');
nr=2;
$(“#拉斯潘”)。文本(nr);
}
});
元(“#t1#e3”)。在({
mouseover:function(){
$(this.css(“背景色”、“黄色”);
$(“#t1#e1”).css(“背景色”、“黄色”);
$(“#t1#e2”).css(“背景色”、“黄色”);
},
mouseleave:function(){
$(this.css(“背景色”、“绿色”);
$(“#t1#e1”).css(“背景色”、“绿色”);
$(“#t1#e2”).css(“背景色”、“绿色”);
},
单击:函数(){
$(此).off('mouseleave');
美元(“#t1#e1”).off('mouseleave');
美元(“#t1#e2”).off('mouseleave');
美元(“#t1#e5”).off('mouseleave');
美元(“#t1#e4”).off('mouseleave');
$(此).off('mouseover');
$(“#t1#e1”).off('mouseover');
$(“#t1#e2”).off('mouseover');
$(“#t1#e5”).off('mouseover');
$(“#t1#e4”).off('mouseover');
$(此).off('click');
$(“#t1#e4”).off('click');
$(“#t1#e2”).off('click');
$(“#t1#e1”).off('click');
$(“#t1#e5”).off('click');
nr=3;
$(“#拉斯潘”)。文本(nr);
}
});
元(“#t1#e4”)。在({
mouseover:function(){
$(this.css(“背景色”、“黄色”);
$(“#t1#e1”).css(“背景色”、“黄色”);
$(“#t1#e2”).css(“背景色”、“黄色”);
$(“#t1#e3”).css(“背景色”、“黄色”);
},
mouseleave:function(){
$(this.css(“背景色”、“绿色”);
$(“#t1#e1”).css(“背景色”、“绿色”);
$(“#t1#e2”).css(“背景色”、“绿色”);
$(“#t1#e3”).css(“背景色”、“绿色”);
},
单击:函数(){
$(此).off('mouseleave');
美元(“#t1#e1”).off('mouseleave');
美元(“#t1#e2”).off('mouseleave');
美元(“#t1#e3”).off('mouseleave');
美元(“#t1#e5”).off('mouseleave');
$(此).off('mouseover');
$(“#t1#e1”).off('mouseover');
$(“#t1#e2”).off('mouseover');
$(“#t1#e3”).off('mouseover');
$(“#t1#e5”).off('mouseover');
$(此).off('click');
$(“#t1#e1”).off('click');
$(“#t1#e2”).off('click');
$(“#t1#e3”).off('click');
$(“#t1#e5”).off('click');
nr=4;
$(“#拉斯潘”)。文本(nr);
}
});
元(“#t1#e5”)。在({
mouseover:function(){
$(this.css(“背景色”、“黄色”);
$(“#t1#e1”).css(“背景色”、“黄色”);
$(“#t1#e2”).css(“背景色”、“黄色”);
$(“#t1#e3”).css(“背景色”、“黄色”);
$(“#t1#e4”).css(“背景色”、“黄色”);
},
mouseleave:function(){
$(this.css(“背景色”、“绿色”);
$(“#t1#e1”).css(“背景色”、“绿色”);
$(“#t1#e2”).css(“背景色”、“绿色”);
$(“#t1#e3”).css(“背景色”、“绿色”);
$(“#t1#e4”).css(“背景色”、“绿色”);
},
单击:函数(){
$(此).off('mouseleave');
美元(“#t1#e1”).off('mouseleave');
美元(“#t1#e2”).off('mouseleave');
美元(“#t1#e3”).off('mouseleave');
美元(“#t1#e4”).off('mouseleave');
$(此).off('mouseover');
$(“#t1#e1”).off('mouseover');
$(“#t1#e2”).off('mouseover');
$(“#t1#e3”).off('mouseover');
$(“#t1#e4”).off('mouseover');
$(此).off('click');
$(“#t1#e1”).off('click');
$(“#t1#e2”).off('click');
$(“#t1#e3”).off('click');
$(“#t1#e5”).off('click');
nr=5;
$(“#拉斯潘”)。文本(nr);
}
});
});
div{
高度:50px;
宽度:200px;
背景:绿色;
}
桌子{
边框颜色:黑色;
边界塌陷:塌陷;
}


正如有人评论的那样,您可以在同一行中使用多个jQuery选择器,因为您对所有选项都使用相同的操作:

$("#e1, #e2, #e3, #e4").off('mouseleave');
此外,如果要删除所有事件,可以不带参数地使用,它将删除所有事件:

$("#e1, #e2, #e3, #e4, #t1").off();
下面是如何在一个操作中处理多个jQuery元素:

var createLines = function(table, randomNumber) {
    for (var i = 1; i <= randomNumber; i++) {
        $('<tr>')
            .addClass('row' + i)
            .appendTo(table)
            .attr('isSelected', 'no')
            .click(clickFunction)
    }
};

var createTables = function(randomNumber) {
    var table = $('<table>');

    createLines(table, randomNumber);
    table.appendTo('body');
};

var clickFunction = function() {
    var $el = $(this);
    var elClass = $el.attr('class');
    var isSelected = $el.attr('isSelected');

    if (isSelected === 'yes') {
        $('.' + elClass).css('background', 'white');
        $el.attr('isSelected', 'no');
    } else {
        $('.' + elClass).css('background', 'yellow');
        $el.attr('isSelected', 'yes');
    }
};

$(document).ready(function() {
    // 1 to 10
    var randomNumber = Math.floor((Math.random() * 10) + 1);

    for (i = 1; i <= 4; i++) {
        createTables(randomNumber);
    }
});
var createLines=函数(表,随机数){

对于(var i=1;i)与您的问题无关,您是否知道
$(“#e1,#e2,