JQuery addition from .text()
JQuery addition from .text()
我有一个变量计数设置为零。
var count = 0;
然后我运行.each()循环来更新计数。text()参数将始终返回一个文本编号。
$(this).find('.outersubtopic').each(function(idx)
{
var temp = $(this).text();
count += temp;
});
alert(count);
当我点击警报时,它总是显示0008,而不是只有8。
如何将.text()转换为实数?
$(this).find('.outersubtopic').each(function(idx)
{
var temp = $(this).text();
count += window.parseInt(temp);
});
alert(count);
window.parseInt()应该为您完成此操作。
您必须将其转换为数字
$(this).find('.outersubtopic').each(function(idx)
{
var temp = $(this).text();
count += Number(temp);
});
alert(count);
尝试使用parseInt
$(this).find('.outersubtopic').each(function(idx)
{
var temp = $(this).text();
count += temp;
});
alert(parseInt(count));
count += 1 * temp; // quick way to change string to number
相关文章:
- 如何将输入(type=text)从html表单传递到javascript函数
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- 在文本区域中使用jQuery.text()保持换行符
- 用Javascript添加带有#text的tr元素
- 当用户按下回车键时,自动在text区域/text中插入消息
- 修正案'text'的元素
- 图像可以从源<img src=""/>.TEXT可以在没有javascript的情况下从外部
- W3验证器->使用<脚本类型=“;text/javascript”>在html的正文中
- Validate JSON from Mongo?
- Get JSON from an url
- 我如何在INPUT TEXT中使用这个Javascript和jQuery
- <text区域>在我的html中包含event.keycode==13之后,wrap就不起作用了
- 从所有下拉菜单中选择val和text
- creating objects from variables ES6
- getDocument by id/get input text from button dons'不起作用
- Kendo UI TreeView dataTextField 和 model.fields.text.from 之间的
- Remove empty lines when copy text from <p>
- JQuery addition from .text()
- Replace text from <option> to <input>
- remove a specific text from <td> element