[英]jquery type error :“TypeError: colorval is undefined,”
Here is console screenshort 这是控制台屏幕短
var color = '';
var xml = '';
function hexc(colorval) {
var parts = $(colorval).match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
delete(parts[0]);
for (var i = 1; i <= 3; ++i) {
parts[i] = parseInt(parts[i]).toString(16);
if (parts[i].length == 1) parts[i] = '0' + parts[i];
}
color = '#' + parts.join('');
}
$("#mcor tr").each(function() {
// alert("1");
xml += '<mcor_info>';
var td_len = $("#mcor tr td").length;
// alert("2");
for (var b = 0; b <= td_len; b++) {
// var index = $('th').eq(b).text();
xml += '<mcor' + b + '>';
var tx = $("#mcor tr ").find("td").eq(b).css('backgroundColor');
hexc(tx);
xml += color;
xml += '</mcor' + b + '>';
}
xml += '</mcor_info>';
});
I am getting this error: Type Error: colorval is undefined
. 我收到此错误:
Type Error: colorval is undefined
。 I found a couple of other examples, tried to solve my error but didn't succeed: 我找到了其他一些示例,试图解决我的错误,但没有成功:
JQuery Type-error e is undefined issue jQuery类型错误e是未定义的问题
Uncaught TypeError: undefined is not a function while using jQuery UI Uncaught TypeError:使用jQuery UI时undefined不是函数
Where is my mistake? 我的错误在哪里?
can you upload the code in jsfiddle, please? 可以在jsfiddle中上传代码吗? I suspect that the problem could be on the line "var tx = $("#mcor tr ").find("td").eq(b).css('backgroundColor');"
我怀疑问题可能出在“ var tx = $(“#mcor tr”).find(“ td”)。eq(b).css('backgroundColor');“
probably it is not getting the result that you think 可能没有得到您认为的结果
UPDATE 更新
what happen if you use that: 如果使用它会发生什么:
var parts = colorval.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
UPDATE #2 更新#2
you can check the code in the following link: 您可以在以下链接中查看代码:
https://plnkr.co/edit/g3boR5yHO895fz76EIKg https://plnkr.co/edit/g3boR5yHO895fz76EIKg
like you can see if I pass a rgb directly to the function it is working fine, that mean that the problem is the "tx" object, that means that you need convert that to string 就像您可以看到我是否直接将rgb传递给它正常工作的函数一样,这意味着问题是“ tx”对象,这意味着您需要将其转换为字符串
hexc(String(tx));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.