当我尝试从函数返回对象并将其分配给 smalls 变量时,变量 smalls 为空,因为它的长度返回为 0。
var smalls = function(){
var table = $("#box-table-a");
return table.find("small");
}, smallContent;
for(var i = 0; i<smalls.length; i++){
smallContent = smalls[i].innerHTML;
smalls[i].parentElement.className += "relative";
smalls[i].className += "form-absolute-right";
smalls[i].innerHTML = "<span class='bubble'>" + smallContent + "<span>";
}
虽然这可行,但可变的小物具有所需的长度。
var table = $("#box-table-a");
var smalls = table.find("small"); //fetch the tr's with <small> tag
var smallContent;
for(var i = 0; i<smalls.length; i++){
smallContent = smalls[i].innerHTML;
smalls[i].parentElement.className += "relative";
smalls[i].className += "form-absolute-right";
smalls[i].innerHTML = "<span class='bubble'>" + smallContent + "<span>";
}
根据我对 Javascript 的了解,可以将函数分配给变量。我究竟做错了什么?