Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从选择下拉菜单获取数据_Javascript_Jquery - Fatal编程技术网

Javascript 从选择下拉菜单获取数据

Javascript 从选择下拉菜单获取数据,javascript,jquery,Javascript,Jquery,我正在使用。一个插件,用于自定义带有图像、文本等的下拉菜单。 当我从下拉列表中选择一个选择选项时,我试图获取文本,但我的浏览器控制台日志显示未定义。我曾尝试将数据放入第7行的变量中,但结果仍然相同 $('#myDropdown').ddslick({ data:ddData, width:300, selectText: "Select your preferred social network", imagePosition:"right", onSel

我正在使用。一个插件,用于自定义带有图像、文本等的下拉菜单。 当我从下拉列表中选择一个选择选项时,我试图获取文本,但我的浏览器控制台日志显示未定义。我曾尝试将数据放入第7行的变量中,但结果仍然相同

$('#myDropdown').ddslick({
    data:ddData,
    width:300,
    selectText: "Select your preferred social network",
    imagePosition:"right",
    onSelected: function(selectedData){
        var selectedData = $('#myDropdown').data('ddslick');
        console.log(selectedData.text);
    }   
});
这是ddData的结构:

var ddData = [{
    text: "Facebook",
    value: 1,
    selected: false,
    description: "Description with Facebook",
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
}, {
    text: "Twitter",
    value: 2,
    selected: false,
    description: "Description with Twitter",
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
}, {
    text: "LinkedIn",
    value: 3,
    selected: true,
    description: "Description with LinkedIn",
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png"
}, {
    text: "Foursquare",
    value: 4,
    selected: false,
    description: "Description with Foursquare",
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png"
}];

我通过Json对象获取数据

之前它只返回[object]

<div id="myDropdown"></div>
    <script type="text/javascript">
        var jsonurl = 'dropDown.html';
        $.ajax({
            type : 'GET',
            url : jsonurl,
            data : {},
            success : function(myData) {
                $('#myDropdown').ddslick({
                    data : myData,
                    width : 300,
                    selectText : "Select the bill process",
                    imagePosition : "right",
                    onSelected : function(selectedData) {
                        alert(selectedData);
                    }
                });
            },
            error : function() {
            }
        });
    </script>
然后我就这样改了

onSelected : function(selectedData) {
                        alert(selectedData);
                    }

onSelected : function(selectedData) {
                        alert(selectedData);
                    }
onSelected : function(myData) {
                        alert(myData.selectedData.text);
                    }