toUpperCase中的jQuery for ...不是函数 [英] jQuery for...in toUpperCase is not a function
本文介绍了toUpperCase中的jQuery for ...不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
典型输入如下...
<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()
不是函数吗?
我需要获取所有大写的数据值.
What I need is to grab all data value in uppercase.
推荐答案
从this $(this).data('value')
返回的值的类型为number
.即:
The value returned from this $(this).data('value')
is of the type number
. I.e:
console.log(typeof $(this).data('value'));
您首先需要检查它是否为number
,然后首先将其转换为string
.像这样:
You first need to check to see if it is a number
, and convert it to a string
first. Like so:
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);
这篇关于toUpperCase中的jQuery for ...不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文