在Jquery中设置值,添加了相同值的两倍

时间:2022-04-24 12:14:01

This is the actual content. While the below code, added a value in dropdown for two times in UI. Shows the dropdown value as "AprilApril" instead of "April"

这是实际内容。在下面的代码中,在UI中的下拉列表中添加了两次值。将下拉值显示为“AprilApril”而不是“April”

 if ($('#dk_container_selectToYear .dk_options li.dk_option_current a').text() == 2016) {
            var currentdate = new Date();
            var month = currentdate.getMonth();
            var monthname = monthLookup[currentdate.getMonth()];
            month = month + 3;
            while (month <= 13) {
                $('#dk_container_selectToMonth .dk_options li:nth-child(' + month + ')').css({ "display": 'none' });
                var listvalue = $('#dk_container_selectToMonth .dk_options li:nth-child(' + month + ')').text();

                if ($('#dk_container_selectToMonth .dk_options li.dk_option_current a').text() == listvalue) {
                    $('#selectToMonth').dropkick('reset');
                    $('#selectToMonth').dropkick('setValue', monthname);
                }

                month++;
            }
        }


$('#selectToMonth').dropkick('setValue', monthname);

Is it have any other option to avoid it..

是否有任何其他选择来避免它..

Thanks in advance..

提前致谢..

1 个解决方案

#1


2  

!!This is not an solution for your question but it is only a hack till you find the solution. Just grab the half of the string.. like this:

!!这不是你的问题的解决方案,但它只是一个黑客,直到你找到解决方案。抓住一半的字符串..像这样:

var monthname = 'AprilApril';
var month = monthname;
console.log(month.substr(0, (month.length/2))); // April
console.log(month) // AprilApril

Enjoy coding!

#1


2  

!!This is not an solution for your question but it is only a hack till you find the solution. Just grab the half of the string.. like this:

!!这不是你的问题的解决方案,但它只是一个黑客,直到你找到解决方案。抓住一半的字符串..像这样:

var monthname = 'AprilApril';
var month = monthname;
console.log(month.substr(0, (month.length/2))); // April
console.log(month) // AprilApril

Enjoy coding!