Javascript 表单元格值读取器无法从 .net Repeater 获取值
我有 JS 函数来读取和总结表列,如下所示:
function calculateValue() {
var sum = 0, index = 0;
var table = document.getElementById("mytab1");
for (var i = 1, row; row = table.rows[i]; i++) {
//alert(row.cells[4].firstChild.nodeValue);
sum += row.cells[4].firstChild.nodeValue;
index++;
}
//alert(sum / index + "_" + sum + "--" + index);
return sum / index;
}
此表(“mytab1”)是一个动态表,一个 .net C# 重复器构建此表。 当我尝试警告这些值时,只有表头有效,其他值是空的,尽管它们内部有值。 有什么想法吗?
我的页面加载函数是:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load_profiles();
ViewState["Time"] = "2";
LoadGoals(2,0); /* this function put List<> in Repeater and creates a table
with the values */
}
}
调用该函数的js部分:
var def = {
百分比:calculateValue() || 0, 规模:100, 限制:真实, 最小值:0, 最大值:100, 后缀: ' %', 动画:真实, 数字卷:真实, 这个CSS:{ 位置:'相对', 宽度:'105px', 高度:'90px', 填充:'0px', 边框:'0px', 字体系列:'Arial', 字体粗细:'250',
},
当表搜索循环中的函数警报时,我可以看到表内的值,并且列标题也用他的值警报。 谢谢。
I have JS function that read and summarize table column like that:
function calculateValue() {
var sum = 0, index = 0;
var table = document.getElementById("mytab1");
for (var i = 1, row; row = table.rows[i]; i++) {
//alert(row.cells[4].firstChild.nodeValue);
sum += row.cells[4].firstChild.nodeValue;
index++;
}
//alert(sum / index + "_" + sum + "--" + index);
return sum / index;
}
This Table ("mytab1") is a dynamic table, a .net C# repeater build this table.
when I try to alert the values, only the table header works, the other values are empty although there are values inside of them.
Any Ideas why?
my page load function is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load_profiles();
ViewState["Time"] = "2";
LoadGoals(2,0); /* this function put List<> in Repeater and creates a table
with the values */
}
}
The js part that calls the function:
var def = {
percentage: calculateValue() || 0,
scale: 100,
limit: true,
minimum: 0,
maximum: 100,
suffix: ' %',
animate: true,
digitalRoll: true,
thisCss: {
position: 'relative',
width: '105px',
height: '90px',
padding: '0px',
border: '0px',
fontFamily: 'Arial',
fontWeight: '250',
},
When the function alert in the table search loop, i can see the values inside the table, and also the Column header is alerting with his value.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议确保您调用 javascript: 的位置
要么是 a) 在
控件之后,要么 b) 在您的页面中添加一些
JQuery,以确保在尝试从 DOM 中读取值之前 DOM 已完全加载桌子。
编辑:
您可能还想使用 JQuery 选择器来访问和求和这些值,而不是使用循环。
I would suggest making sure that where you call your javascript:
is either a) after the
control, or b) add a
bit of JQuery to your page to make sure that the DOM has been fully loaded before you try to read the values from the table.
EDIT:
You may also want to use a JQuery selector to access and sum the values instead of using your loop.