我需要使用http://designwithpc.com/plugins/ddslick中的图像下拉列表,我试图在回发后设置“ selected”选项,但是我得到了无限次回发。这是我的代码:

<form id="form1">
<select id="localeId" name="localeId"></select>
</form>

<script type="text/javascript">
        //Dropdown plugin data
        var ddData = [
            {
                text: "English",
                value: "en",
                selected: false,
                description: "English",
                imageSrc: "/assets/img/flags-icons/en-flag.png"
            },
            {
                text: "Portuguese",
                value: "pt",
                selected: false,
                description: "Portuguese",
                imageSrc: "/assets/img/flags-icons/pt-flag.png"
            },
            {
                text: "Russian",
                value: "ru",
                selected: false,
                description: "Russian",
                imageSrc: "/assets/img/flags-icons/ru-flag.png"
            },
            {
                text: "Spanish",
                value: "es",
                selected: false,
                description: "Spanish",
                imageSrc: "/assets/img/flags-icons/es-flag.png"
            }
        ];

        $('#localeId').ddslick({
            data: ddData,
            defaultSelectedIndex: 3,
            onSelected: function (data) {
                if (data.selectedIndex > 0) {
                    $('#hidCflag').val(data.selectedData.value);
                    $.cookie('lang', document.getElementById("hidCflag").value, { expires: 365 });
                    form1.submit();
                }

            }
        });
    </script>


能帮我解决吗?

最佳答案

您可以使用插件的选择方法,例如

$('#demoSetSelected').ddslick('select', {index: i });


选择一个特定的索引。

根据他们网站上的ddSlick演示#4(http://designwithpc.com/plugins/ddslick#demo

关于javascript - 回发后如何使用ddSlick将选项设置为选项?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31072053/

10-11 14:16