javascript - 命令
问题描述
我正在使用 jQuery UI 可排序元素。我的 jQuery 脚本在用户选中某些框时生成。但我也有一个选择允许用户定义他想要的布局。
当他单击选择器中的默认值时,我想定义<li>
顺序,或者至少我希望它们在我的页面中首次显示时返回。
你有什么解决办法吗?(我使用 jQuery && jQuery UI)
这是我的代码:
$('#layout_choice').change(function(){
window.layout_choice = $(this).val();
//change li and ul id name
$('#sortable > li').each(function(){
let tmp_id = $(this).attr('id')
tmp_id = tmp_id.replace(/([a-z]{3,8}\_\Bblock\B\_)[a-z]{4,7}/i, "$1" + window.layout_choice);
$(this).attr('id', tmp_id);
})
//changing ul by replacing witg regex his class name
let tmp_class_ul = $('#sortable').attr('class').split(' ')[2];
$('#sortable').removeClass(tmp_class_ul)
tmp_class_ul = tmp_class_ul.replace(/(\bsortable)(\_)?([a-z]{4,7})?/i, "$1" + "\_" + window.layout_choice);
$('#sortable').addClass(tmp_class_ul);
// disable sorting if user layout choice set on 'default'
if(window.layout_choice == 'default') $('#sortable').sortable('disable')
else $('#sortable').sortable('enable')
if($(this).has('default')){
// display them back with correct order.
}
})
<!-- Choice display manager-->
<div class="col">
<span class="badge badge-default">Choose the position of your selected elements</span>
<select class="mt-1" id="layout_choice" name="layout_format">
<option selected disabled>--SELECT A LAYOUT TYPE--</option>
<option value="default">Default (non customizable)</option>
<option value="mini">Mini format customizable</option>
<option value="full">Full customizable</option>
<option value="" disabled>Customizable by lines</option>
</select>
<ul id="sortable" class="sortable_ul">
<!-- <li> for each category of information we will display in the builder -->
</ul>
<input class="d-none" type="text" id="categories_order" name="order">
</div>
知道如何在不删除每个并以正确顺序替换每个的情况下怎么做。谢谢 !
解决方案
推荐阅读
- javascript - 使用 vanilla javascript 计算滚动位置
- c# - UWP 自定义 Sqlite 查询到 JSON
- javascript - GitHub工作流程陆续启动
- ios - 如果用户不授予在 iOS14 上跟踪的权限,我是否需要禁用社交媒体登录?
- github - GitHub CICD 的大文件
- c# - Xamarin Android ForceDarkHelper 是什么?
- lua - Lua ffi.load 找不到没有绝对路径的库
- temporary-objects - 临时物化转换 - 术语和概念的混淆
- python - 如何使用 scala 进程实用程序发送 EOF
- javascript - 如何在单击特定选项卡后立即为折线图制作动画?