腳本:JQuery的每個函數?
var degress = GiveDegrees();
$(function() {
//alert(GiveDegrees()); //output: 89,91,87,90,91
});
function GiveDegrees() {
var divs = $('p.wx-temp');
var degrees = new Array();
$.each(divs, function (i, j) {
degrees.push(stringToNum($(this).text()));
});
return degrees;
}
function stringToNum(str) {
return str.match(/\d+/g);
}
我有這樣的:
$("p.wx-temp").each(degress, function (index) {
$(this).append(degress[index], "<sup>°C</sup>");
alert("I works");
});
,但它不能正常工作。當我這樣寫:
$("p.wx-temp").each(function (index) {
$(this).append("<sup>°C</sup>");
alert("I works");
});
它的工作原理。 .each()
函數.each(data, function (index))
是否沒有過載方法?
度數組是包含五個int的整數數組,如89,91,87,90,91
。如何使用.each
函數將數組值添加到每個p
元素。
謝謝。
'{89,91,87,90,91}'是不是有效的對象。 –
它的整數數組。它只顯示不是真實的格式。 –