javascript - 在每个 javascript 中获取多个值
问题描述
我必须在 n 个 li 的长 ul 中附加一个 li。lis 的位置需要是第 10、20、30 等等。这是我的代码。当我使用静态数字运行时,它工作正常,但是当我使用变量运行时,它不起作用。原因是数字永远不等于变量。我的代码有什么错误,有人可以帮忙吗?
require(['jquery', 'jquery/ui', 'domReady!'], function(jquery) {
jquery(document).ready(function() {
jquery("ol#list > li").each(function(index) {
var getXth = '';
var tenth = 10;
var str = parseInt(index);
var getTenth = parseInt(str * 10);
var b = 8;
var getXth = parseInt(getTenth, 10) + parseInt(b, 10);
alert(index);
alert('this' + getXth);
//var getXth = parseInt(str) * tenth;
//var getValTenth = getXth - 2;
//alert(typeof sum);
/*index == 1 || index == 8 || index == 18 || index == 28 || index == 38 || index == 48 || index == 58 || index == 68 || index == 78 || index == 88 || index == 98 || index == 108 || index == 118 || index == 128 || index == 138 || index == 148 || index == 158 || index == 168 || index == 178 || index == 188 || index == 198 || index == 208 || index == 218 || index == 228 || index == 238 || index == 248 || index == 258 || index == 268 || index == 278 || index == 288*/
//index == (parseInt(getTenth))
if (index == getXth) {
jquery('#list > li:eq(' + index + ')').after('<li class="item product product-item col-lg-4 col-md-4 col-sm-4 col-xs-6">' + jquery("div.tenth-product-block").html() + '</li>');
}
var getXth = '';
//index +=1;
});
});
});
解决方案
if(index%10 == 1) {
jquery('#list > li:eq('+index+')').after('<li class="item product product-item col-lg-4 col-md-4 col-sm-4 col-xs-6">'+jquery("div.tenth-product-block").html()+'</li>');
}
这是我的代码。正如我在函数之后使用的,所以它在之后添加了 html。
推荐阅读
- android - 如何从 lstBook = new ArrayList<>() 设置 Android Intent.ACTION_CALL, Uri number;
- objective-c - 如何检查 NSString 语言是否匹配 NSLocaleLanguageCode
- java - ROSJAVA org.ros.internal.message 无法转换为 std_msgs.String
- python - azure 机器学习工作台 - 准确度高但置信度分数非常低
- junit4 - Junit 测试异常
- apache-spark - 如何为大型数据帧更快地触发 count()?
- spring - Spring Boot以不同的顺序加载日志类
- reactjs - 我可以将“数组或迭代器中的每个孩子都应该有一个唯一的“关键”道具”警告变成错误吗?
- android - 如何在android上并排制作一个按钮和彩色矩形?
- python - 如何使用 google-auth 实例化 Google API 服务?