Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
完成另一个JS后加载的Javascript CSS_Javascript_Jquery_Html_Css_Ajax - Fatal编程技术网

完成另一个JS后加载的Javascript CSS

完成另一个JS后加载的Javascript CSS,javascript,jquery,html,css,ajax,Javascript,Jquery,Html,Css,Ajax,我有一个Javascript,它根据td表中的值将td表的颜色转换为特定的颜色: $(document).ready(function () { $('#headerTbl td').each(function () { if (parseInt($(this).text(), 10) >= 0 && parseInt($(this).text(), 10) <= 69) { $(this).cs

我有一个Javascript,它根据td表中的值将td表的颜色转换为特定的颜色:

$(document).ready(function () {
        $('#headerTbl td').each(function () {
            if (parseInt($(this).text(), 10) >= 0 && parseInt($(this).text(), 10) <= 69) {
                $(this).css('background-color', '#F15854');
            }
            else if (parseInt($(this).text(), 10) >= 70 && parseInt($(this).text(), 10) <= 89) {
                $(this).css('background-color', '#DECF3F');
            }
            else if (parseInt($(this).text(), 10) >= 90 && parseInt($(this).text(), 10) <= 100) {
                $(this).css('background-color', '#5DA5DA');
            }
        })
       });
$(文档).ready(函数(){
$('#headerTbl td')。每个(函数(){

如果(parseInt($(this.text(),10)>=0&&parseInt($(this.text(),10)=70&&parseInt($(this.text(),10)=90&&parseInt($(this.text(),10)再次运行它。首先,将它隔离到自己的函数中:

function setBackgroundsOnCells() {
    $('#headerTbl td').each(function() {
        if (parseInt($(this).text(), 10) >= 0 && parseInt($(this).text(), 10) <= 69) {
            $(this).css('background-color', '#F15854');
        }
        else if (parseInt($(this).text(), 10) >= 70 && parseInt($(this).text(), 10) <= 89) {
            $(this).css('background-color', '#DECF3F');
        }
        else if (parseInt($(this).text(), 10) >= 90 && parseInt($(this).text(), 10) <= 100) {
            $(this).css('background-color', '#5DA5DA');
        }
    })
}
函数setBackgroundsOnCells(){
$('#headerTbl td')。每个(函数(){

如果(parseInt($(this.text(),10)>=0&&parseInt($(this.text(),10)=70&&parseInt($(this.text(),10)=90&&parseInt($(this.text(),10)再次运行它。首先,将它隔离到自己的函数中:

function setBackgroundsOnCells() {
    $('#headerTbl td').each(function() {
        if (parseInt($(this).text(), 10) >= 0 && parseInt($(this).text(), 10) <= 69) {
            $(this).css('background-color', '#F15854');
        }
        else if (parseInt($(this).text(), 10) >= 70 && parseInt($(this).text(), 10) <= 89) {
            $(this).css('background-color', '#DECF3F');
        }
        else if (parseInt($(this).text(), 10) >= 90 && parseInt($(this).text(), 10) <= 100) {
            $(this).css('background-color', '#5DA5DA');
        }
    })
}
函数setBackgroundsOnCells(){
$('#headerTbl td')。每个(函数(){

如果(parseInt($(this.text(),10)>=0&&parseInt($(this.text(),10)=70&&parseInt($(this.text(),10)=90&&parseInt($(this.text(),10)调用document.ready中的css编辑代码,这是执行的第一件事,直到那时td都不存在

在开始编辑之前,您需要先获取数据并创建表结构

这样做

function getData() {

    var $tblpercent = $('#headerTbl');
    $.ajax({
        url: '../api/data',
        type: 'GET',
        datatype: 'json',
        success: function (data) {

            if (data.length > 0) {
                $tbl.empty();
                var rows2 = [];
                for (var i = 0; i < data.length; i++) {
                    rows2.push('<td>' + data[i].percentage + '</td>');
                }

                $tblpercent.append(rows2.join(''));
            }

            $('#headerTbl td').each(function () {
                if (parseInt($(this).text(), 10) >= 0 && parseInt($(this).text(), 10) <= 69) {
                    $(this).css('background-color', '#F15854');
                }
                else if (parseInt($(this).text(), 10) >= 70 && parseInt($(this).text(), 10) <= 89) {
                    $(this).css('background-color', '#DECF3F');
                }
                else if (parseInt($(this).text(), 10) >= 90 && parseInt($(this).text(), 10) <= 100) {
                    $(this).css('background-color', '#5DA5DA');
                }
            })
        }
    });
};
函数getData(){ 变量$tblpercent=$(“#headerTbl”); $.ajax({ url:“../api/data”, 键入:“GET”, 数据类型:“json”, 成功:功能(数据){ 如果(data.length>0){ $tbl.empty(); var rows2=[]; 对于(变量i=0;i如果(parseInt($(this.text(),10)>=0&&parseInt($(this.text(),10)=70&&parseInt($(this.text(),10)=90&&parseInt($(this.text(),10)调用document.ready中的css编辑代码,这是执行的第一件事,直到那时td都不存在

在开始编辑之前,您需要先获取数据并创建表结构

这样做

function getData() {

    var $tblpercent = $('#headerTbl');
    $.ajax({
        url: '../api/data',
        type: 'GET',
        datatype: 'json',
        success: function (data) {

            if (data.length > 0) {
                $tbl.empty();
                var rows2 = [];
                for (var i = 0; i < data.length; i++) {
                    rows2.push('<td>' + data[i].percentage + '</td>');
                }

                $tblpercent.append(rows2.join(''));
            }

            $('#headerTbl td').each(function () {
                if (parseInt($(this).text(), 10) >= 0 && parseInt($(this).text(), 10) <= 69) {
                    $(this).css('background-color', '#F15854');
                }
                else if (parseInt($(this).text(), 10) >= 70 && parseInt($(this).text(), 10) <= 89) {
                    $(this).css('background-color', '#DECF3F');
                }
                else if (parseInt($(this).text(), 10) >= 90 && parseInt($(this).text(), 10) <= 100) {
                    $(this).css('background-color', '#5DA5DA');
                }
            })
        }
    });
};
函数getData(){ 变量$tblpercent=$(“#headerTbl”); $.ajax({ url:“../api/data”, 键入:“GET”, 数据类型:“json”, 成功:功能(数据){ 如果(data.length>0){ $tbl.empty(); var rows2=[]; 对于(变量i=0;i如果(parseInt($(this.text(),10)>=0&&parseInt($(this.text(),10)=70&&parseInt($(this.text(),10)=90&&parseInt($(this.text(),10)尝试在您的应用程序中将async设置为falseAJAX@RohanVeer-不,在主线程上运行同步XMLHttpRequests不会有什么区别,在主线程中尝试将async设置为false是一种不好的做法AJAX@RohanVeer-不,在主线程上运行同步XMLHttpRequests不会有什么不同,这是一种不好的做法非常感谢您的回答:D。哦,背景色只是为了实验,谢谢你的推荐。非常感谢你的回答:D。哦,背景色只是为了实验,谢谢你的推荐。谢谢@MGA这很有帮助!:D谢谢@MGA这很有帮助!:D