如何通过ID在一个div上执行此javascript?

时间:2022-11-25 20:01:16

I have attempted to add document.getElementByID("#divname") but it hasn't work yet. I am learning on the fly and appreciate help that stack overflow users.

我试图添加document.getElementByID(“#divname”)但它还没有工作。我正在学习,并欣赏堆栈溢出用户的帮助。

$(document).ready(function() {

promise = $.ajax({
    type:"GET",
    dataType:"text",
    url:"sgi.csv",
    cache:false
});

promise.done(function(data){

    var dataArr = data.split("\n");

    $.each(dataArr,function(){
        if (this != "") {

            var row = new String("");
            valArr = this.split(",");
                row += "<tr>"

            $.each(valArr, function(){
                row += "<td>" + this +"</td>"
            });     

                row += "</tr>"

             $('tbody').append(row);

        }

    });

});

// Run script if request fails
promise.fail(function() {
   console.log('A failure ocurred');
});

});

1 个解决方案

#1


0  

document.getElementById('divName').append(var)

#1


0  

document.getElementById('divName').append(var)