How to set up a click event for a dropdown box in layui?
In Layui, you can achieve the corresponding operation by listening to the click event of the dropdown box. Here is a simple example:
HTML code:
<select id="selectDemo">
<option value="1">选项一</option>
<option value="2">选项二</option>
<option value="3">选项三</option>
</select>
JavaScript code:
layui.use(['form'], function() {
var form = layui.form;
// 监听下拉框的点击事件
form.on('select(selectDemo)', function(data) {
var value = data.value; // 获取选中的值
console.log(value);
// 这里可以根据选中的值执行相应的操作
});
});
In the code above, we utilized Layui’s form module and select box selector. We listened to the click event of the select box by using form.on(‘select(selectDemo)’, function(data) {}), where selectDemo is the id of the select box.
In the callback function for the event listener, you can use data.value to retrieve the selected value and then perform relevant operations based on specific needs.