gpt4 book ai didi

javascript - 如何在 jquery 中将数组列表连接到常量值

转载 作者:行者123 更新时间:2023-12-03 02:44:40 25 4
gpt4 key购买 nike

我在 jQuery 中有一个名为Assignedmonth 的变量,它存储从下拉列表中选择的多个项目

AssignedMonth = $('#dlAssignedMonth :selected').map(function () { return $(this).text(); }).get();

还有一个变量AssignedYear,它仅存储从列表中选择的一项。

AssignedYear = $('#dlAssignedYear').val();

现在我想连接这两个变量并希望结果采用以下格式。

Jan-2017
Feb-2017
Mar-2017

本月剩余时间也是如此。

我在js文件中尝试了$.each()函数,但无法获得所需的结果。

最佳答案

返回之前只需在 $(this).text() 中添加年份前缀

var year = $('#dlAssignedYear').val();

var output = $('#dlAssignedMonth :selected').map( function () {
return year + " " + $(this).text(); //this line has been changed to prefix year
}).get();

关于javascript - 如何在 jquery 中将数组列表连接到常量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48148815/

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