gpt4 book ai didi

javascript - 如何从引导多选中获取当前点击事件文本

转载 作者:行者123 更新时间:2023-12-03 04:15:54 25 4
gpt4 key购买 nike

我试图从多选中获取当前单击的选项文本。但仅在更改事件上有效。点击事件不起作用,请检查

$('#myoption').change(function () {
alert($(this).children("option").text());
});

最佳答案

您可以使用:

onChange: A function which is triggered on the change event of the options. Note that the event is not triggered when selecting or deselecting options using the select and deselect methods provided by the plugin.

$('#example-getting-started').multiselect({
onChange: function(option, checked, select) {
console.log('Changed option ' + $(option).val() + '.');
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css">
<script src="https://rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"></script>

<div class="container">
<select id="example-getting-started" multiple="multiple">
<option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option>
</select>
</div>

关于javascript - 如何从引导多选中获取当前点击事件文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com