脚本:
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 as 的整数数组89,91,87,90,91。如何使用.each函数将数组值添加到每个p元素。
谢谢。