2026/1/11 10:22:40
网站建设
项目流程
专业的丹阳网站建设,短视频app成品搭建源码免费,怎样做免费抽皮肤的网站,wordpress要收钱吗jQuery EasyUI 拖放 - 创建学校课程表
使用 jQuery EasyUI 的 draggable 和 droppable 插件#xff0c;可以轻松实现一个交互式的学校课程表#xff08;Timetable#xff09;。左侧显示可选课程科目#xff0c;用户可以将科目拖动到右侧的课程表单元格中安排课表。支持从左…jQuery EasyUI 拖放 - 创建学校课程表使用jQuery EasyUI的draggable和droppable插件可以轻松实现一个交互式的学校课程表Timetable。左侧显示可选课程科目用户可以将科目拖动到右侧的课程表单元格中安排课表。支持从左侧拖入克隆添加和在课程表内拖动调整位置。这个示例模拟一个简单的排课系统左侧是课程列表右侧是按星期和节次划分的表格。官方教程参考https://www.jeasyui.com/tutorial/dd/dnd3.php在线 Demohttps://www.jeasyui.com/tutorial/dd/dnd3_demo.html步骤 1: 引入 EasyUI 资源linkrelstylesheettypetext/csshrefhttps://www.jeasyui.com/easyui/themes/default/easyui.csslinkrelstylesheettypetext/csshrefhttps://www.jeasyui.com/easyui/themes/icon.cssscripttypetext/javascriptsrchttps://code.jquery.com/jquery-1.12.4.min.js/scriptscripttypetext/javascriptsrchttps://www.jeasyui.com/easyui/jquery.easyui.min.js/script步骤 2: 创建 HTML 结构左侧课程区多个可拖动 div右侧课程表table 的 td 为放置区。divstylemargin:20px 0;/divdivclasseasyui-panelstylewidth:800px;padding:10px;tablestylewidth:100%trtdvaligntoph3可选课程/h3divclassitem语文brTeacher: Mr.Wang/divdivclassitem数学brTeacher: Mr.Xu/divdivclassitem英语brTeacher: Miss.Liu/divdivclassitem物理brTeacher: Mr.Zhao/divdivclassitem化学brTeacher: Mr.Chen/divdivclassitem体育brTeacher: Mr.Li/div/tdtdvaligntopstylepadding-left:50px;h3课程表/h3tableclasstimetabletrth/thth星期一/thth星期二/thth星期三/thth星期四/thth星期五/th/trtrtd第1节/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/td/trtrtd第2节/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/td/trtrtd第3节/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/td/trtrtd第4节/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/td/trtrtd第5节/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/tdtdclassdrop/td/tr/table/td/tr/table/divstyle.item{width:120px;height:60px;margin:10px;padding:10px;text-align:center;background:#fafafa;border:1px solid #ccc;cursor:move;}.timetable th, .timetable td{border:1px solid #ccc;padding:10px;text-align:center;width:100px;height:80px;vertical-align:top;}.timetable .drop{background:#fff;}.timetable .over{background:#ff0;}/style步骤 3: JavaScript 实现拖放逻辑使课程可拖动clone 代理课程表单元格可放置从左侧拖入克隆添加从表格内拖动则移动。scripttypetext/javascript$(function(){// 左侧课程可拖动克隆$(.item).draggable({revert:true,proxy:clone,onStartDrag:function(){$(this).draggable(options).cursornot-allowed;},onStopDrag:function(){$(this).draggable(options).cursormove;}});// 课程表单元格可放置$(.timetable td.drop).droppable({onDragEnter:function(e,source){$(this).addClass(over);},onDragLeave:function(e,source){$(this).removeClass(over);},onDrop:function(e,source){$(this).removeClass(over);if($(source).hasClass(assigned)){// 从表格内拖动移动$(this).append(source);}else{// 从左侧拖入克隆添加varclone$(source).clone().addClass(assigned);$(this).empty().append(clone);clone.draggable({revert:true// 允许在表格内继续拖动调整});}}});});/script关键说明从左侧拖入使用proxy:clone放置时克隆课程并添加assigned类标记已安排。在表格内调整已安排的课程.assigned拖动时直接移动元素。视觉反馈拖入单元格时高亮.over类。revert: true无效放置时回弹。优势直观排课支持调整位置可扩展清除/保存功能。扩展建议添加“清除”按钮在单元格右键或双击清除课程。支持保存拖放后收集所有安排的课程AJAX 提交到后端。防止重复/冲突onDrop 时检查单元格是否已有课程。更多节次/星期动态生成表格。更多示例官方学校课程表示例https://www.jeasyui.com/tutorial/dd/dnd3.phpDemo 下载可在官方教程页查找 ZIP。如果需要添加保存功能、冲突检测、完整源码或更多课程数据请提供更多细节