gpt4 book ai didi

javascript - 无法使用 jQuery 创建嵌套元素

转载 作者:行者123 更新时间:2023-11-28 11:53:25 26 4
gpt4 key购买 nike

所以我想编写一个函数来返回列表元素,其中包含一些内容,即

function generateSurpriseMe(month) {
var surprise = $('

<li class="queue-month">
<h3>'+ month +'</h3>
...
</li>

');

return surprise;

}

其中月份是需要插入其中的参数(它不是唯一的参数,但为了简单起见,我只包含它)。但我在控制台中收到“Unexpected token ILLEGAL”错误,并且无法弄清楚它是什么,错误引用了第二行代码 varsurprise = $('

最佳答案

多行字符串应以 \ 结尾

var surprise = $('\
\
<li class="queue-month">\
<h3>'+ month +'</h3>\
...\
</li>\
\
');

参见this了解更多详情

关于javascript - 无法使用 jQuery 创建嵌套元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31209358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com