请原谅我完全缺乏知识,我对这一切都很陌生。我在这里找到了一些代码,它们可以满足我的需求,因此我正在尝试对其进行调整。基本上我需要在屏幕上显示一个字符,然后使用下拉列表更改该字符
这是 HTML
<div style = "position: absolute; left: 320; top: 700;" class = "dropdown-menu- portfolio" >
<select id="category-navbar" name="category-navbar" style="width: 131px;">
<option value="1">motif 1</option>
<option value="2">motif 2</option>
<option value="3">motif 3</option>
</select>
Java 脚本
<script>
$(".category-navbar value value").click(function() {
// Modifying the label
$('div.dropdown-menu-portfolio label').text($(this).text());
// Removing the class 'select' to the item previously selected
$('option.select').removeClass('select');
// Giving the class 'select' to the item currently selected
$(this).parent().addClass('select');
});
</script>
我已经为这个打开和关闭而苦苦挣扎了几个星期,真的很想破解它。任何帮助将不胜感激!
最佳答案
我不是 100% 确定,但我认为这就是您要找的:
$(document.body).on('change', 'select#category-navbar', function() {
$('.selected-value').text($(this).val());
});
因此,当您更改下拉列表中的选项时,它会将选定的选项值写入 .selected-value div 中。演示:http://jsfiddle.net/qp2b9Lof/
关于javascript - 使用下拉列表 java/html/css 将字符写入 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26617797/