繁体   English   中英

函数无法将代码从数组正确输出到div

[英]Function not outputting code from array into div correctly

我正在尝试使用以下脚本将名称输出到列表中:

var names = ["JakeP97", "Trishy", "Puffs", "Evilgenious", "Joeyc", "TheKid"];
var ballots = ["#book1", "#book2", "#book3", "#book4", "#book5", "#book6"];

function splitName(plName,ballotNum) {
    var halfplName = Math.round(plName.length / 2);
    var firstplName = plName.substr(0, halfplName);
    var lastplName = plName.substr(halfplName, plName.length);
    $(ballotNum + 'ul.hardcover_front').find('li:nth-child(2)').html(firstplName);
    $(ballotNum + 'ul.hardcover_back').find('li:nth-child(1)').html(lastplName);
}

for (i=0; i<ballots.length; i++) {
    splitName(names[i],ballots[i]);
}

不幸的是,它没有输出代码,并且我没有收到任何语法错误,并且问题一定存在于我未发现的逻辑中。

我在这里摆弄着小提琴,上面有为大家编写的代码。 链接到小提琴

让我知道是否有更多信息可以帮助您。 谢谢

我认为您忘记在jsfiddle中添加jquery库,并且需要在两者之间添加空间

ballotNum + ' ul.hardcover'

结果

希望有帮助,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM