【问题标题】:How to place a Jquery object to html element and vice-versa如何将 Jquery 对象放置到 html 元素,反之亦然
【发布时间】:2014-08-20 02:06:36
【问题描述】:

我正在尝试按照教授的要求将我的纯 JavaScript 代码转换为 jQuery 代码块。唯一缺少的是下面。 当我尝试使用“thumbs”变量时,它在 jQuery 格式中不起作用。有光吗?请!

工作... 它是:

$(document).ready(function(){
function displayThumbFound(found){ // for week lab 4
    htmlStrFound = "";
    var thumbs = document.getElementById('thumbnails');
    var count = 0;

    // Print columns content
    for(var i = 0; i < 3; i++){
        // Print lines' content
        for(var j = 0; j < found.length; j++){
            [...]
            }
        thumbs.innerHTML = htmlStrFound;            
    }
}   
});

不工作... 应该是:

$(document).ready(function(){
function displayThumbFound(found){ // for week lab 4
    htmlStrFound = "";
    var thumbs = $('#thumbnails');
    var count = 0;

    // Print columns content
    for(var i = 0; i < 3; i++){
        // Print lines' content
        for(var j = 0; j < found.length; j++){
            [...]
            }
        thumbs.html= htmlStrFound;      
    }
}   
});

【问题讨论】:

    标签: jquery html innerhtml


    【解决方案1】:

    你需要改变

    thumbs.html= htmlStrFound;
    

    thumbs.html(htmlStrFound);
    

    【讨论】:

      【解决方案2】:

      .html 不是属性而是函数

      因此将其用作

      thumbs.html('String');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-05
        • 2011-06-24
        • 1970-01-01
        • 2015-12-09
        • 1970-01-01
        • 2011-05-10
        • 1970-01-01
        相关资源
        最近更新 更多