我需要一个带图标的下拉列表,并找到此网站msdropdown。我正在使用代码,我想通过“选择”中的Javascript选择一个选项。问题是,当我选择该选项时,不会显示该标志。不幸的是,我一点都不熟悉JQuery。我认为问题在于,通过Javscript选择一种语言时,不会加载国家/地区标记。
<html>
<head>
<script src="script/jquery/jquery-1.9.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/msdropdown/dd.css" />
<script src="script/msdropdown/jquery.dd.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/msdropdown/flags.css" />
<script>
$(document).ready(function(e) {
$("#countries").msDropdown(); //image can have css class; Please check source code.
});
function button_en() {
//first attempt
var $select = $('.test_1');
$select.val("en"); // (1)
//seconde attempt
$('#countries option[value="en"]').msDropdown();
}
function button_de() {
//third attempt
document.getElementById('countries').value = "de";
}
</script>
</head>
<body>
<select class="test_1" name="countries" id="countries" style="width:110px;">
<option value="de" data-thumbnail="Download.jpg">Deutsch</option>
<option value="en" data-thumbnail="Download.png">English</option>
</select>
<input type="button" value="English" onclick="button_en();" style="width:120px">
<input type="button" value="Deutsch" onclick="button_de();" style="width:120px">
</body>
</html>