典型输入如下...
<input type="checkbox" class="actEmail" data-value="1"/>Department one</li>
在我的函数中...
var chksDept = $('input[type=checkbox].actEmail:checked');
var depts = Array();
chksDept.each(function() {
depts.push($(this).data('value').toUpperCase());
});
为什么我收到错误:
$(...).data(...).toUpperCase()
is not a function?
我需要的是获取所有大写的数据值。
最佳答案
从 this $(this).data('value')
返回的值是 number
类型。即:
console.log(typeof $(this).data('value'));
您首先需要检查它是否是一个数字
,然后将其转换为字符串
。就像这样:
var chksDept = $('input[type=checkbox].actEmail:checked');
var depts = Array();
chksDept.each(function() {
var data = $(this).data('value');
if (typeof data === 'number') {
data = ""+data;
}
depts.push(data.toUpperCase());
});
console.log(depts);
关于jQuery for...in toUpperCase 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16208776/