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

时间:2016-04-12 08:11:53

标签: javascript jquery duplicates setvalue

这是实际内容。在下面的代码中,在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);

是否还有其他选择可以避免它..

提前致谢..

1 个答案:

答案 0 :(得分:2)

!!这不是您问题的解决方案,但只有在您找到解决方案之前它才是黑客攻击。 抓住一半的字符串......就像这样:

<script>
 var classNumber = document.getElementById('rankdos'); //RANK BILDE 1
classNumber.onchange = runBackgroundChangeDos;

function runBackgroundChangeDos(first){
    var value = first.srcElement.options[first.srcElement.selectedIndex].value;
var h1 = //HERE I LOOOKING FOR WHAT TO TYPE TO GET VALUE OF SELECT WHIT ID rankono
    if (value == 0) {
        document.getElementById('rankimgdos').style.backgroundImage="url('http://localhost/36h8f93.png')"; 
        document.getElementById("PriceFrame").src = "http://www.nordicelite.net/testing/payment.php?crank="h1"&drank=0"; //here i need h1 to show value of select whit id rankono
    } else {
        document.getElementById('rankimgdos').style.backgroundImage="url('http://localhost/rgeg.png')";
    document.getElementById("rankto").innerHTML = "None";
    };
}
</script>

享受编码!