js 给select 绑定改变后的事件onchange
当id 为action的select 标签发生改变时,执行handleChange() 方法
select id="action" onchange="handleChange()"
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div> <form action="/upload" method="post" enctype="multipart/form-data"> <input type="hidden" style="display: none" placeholder="id" name="announcement_id" value="{{ announcement.id }}" > <br> <input type="text" size="60" value="{{ announcement.name }}" disabled> <br> <textarea style="width: 431px; height: 343px" disabled> {{ announcement.content }}</textarea> <br> <span>变更结束时间:</span><input id="end_time" disabled type="datetime-local" name="end_time" value="now" > <br> <select id="action" onchange="handleChange()" name="select" style="width: 392px;"> <option value="over">变更结束</option> <option value="delay">推迟结束时间</option> </select> <button type="submit" value="提交">提交</button> </form> </div> <script> // 选择select 后触发动作 function handleChange() { var obj = document.getElementById('action'); // 定位id var index = obj.selectedIndex; // 选中索引 var value = obj.options[index].value; // 选中值 if (value == "delay" )( document.getElementById("end_time").value= {{ announcement.end_time }} )else if (value == "over" )( document.getElementById("end_time").value=now ) {#alert(value);#} } </script> </body> </html>
posted on 2023-03-29 21:00 zhangmingda 阅读(652) 评论(0) 编辑 收藏 举报