Javascript Sortable Js在带有Select/Option标记的chrome中不起作用,但在ul/li标记中起作用
我需要一个帮助,在排序我的文字按照他们的顺序。我使用了可排序js来排序它们的顺序。我已经在select/option标签中实现了它。它在mozilla中运行良好,但在chrome中不起作用。但当我使用ul/li标签时,它在两种浏览器中都可以正常工作。有人能帮我在select/option标签中完成这项任务吗 这是演示: 这是文件链接: 提前通知Javascript Sortable Js在带有Select/Option标记的chrome中不起作用,但在ul/li标记中起作用,javascript,rubaxa-sortable,Javascript,Rubaxa Sortable,我需要一个帮助,在排序我的文字按照他们的顺序。我使用了可排序js来排序它们的顺序。我已经在select/option标签中实现了它。它在mozilla中运行良好,但在chrome中不起作用。但当我使用ul/li标签时,它在两种浏览器中都可以正常工作。有人能帮我在select/option标签中完成这项任务吗 这是演示: 这是文件链接: 提前通知 <!DOCTYPE html> <html> <head></head> <body>
<!DOCTYPE html>
<html>
<head></head>
<body>
<select id="foo1" multiple>
<option value="1">Sunny Thakur</option>
<option value="2">Deepak kanyan</option>
<option value="3">Harpreet Singh</option>
<option value="4">karmjeet Singh</option>
<option value="5">Gurvinder Singh</option>
</select>
<script src="Sortable.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="st/app.js"></script>
</body>
</html>
我现在能想到的唯一解决方案是使用JavaScript和CSS创建自己的自定义选择列表小部件。这是我从《圣经》中借用的一个概念。这里有一个链接,你可以在Chrome上测试它的实时版本 HTML JavaScript
我现在能想到的唯一解决方案是使用JavaScript和CSS创建自己的自定义选择列表小部件。这是我从《圣经》中借用的一个概念。这里有一个链接,你可以在Chrome上测试它的实时版本 HTML JavaScript
您可以发布您的html结构和用于初始化可排序库的JavaScript代码吗?您可以从我上面提到的链接获取js文件。谢谢你重播我。谢谢你发布的html。你应该编辑你的答案并把它贴在那里。在回答中发布后,您可以选择您发布的代码,然后单击{}图标,它会将您的html格式化为代码,这样每个人都可以以更可读的格式查看。谢谢您的指导。没问题,我已经建立了一个基本的测试环境,我会看看我能做些什么。你能发布你的html结构和用来初始化可排序库的JavaScript代码吗?你可以从我上面提到的链接获取js文件。谢谢你重播我。谢谢你发布的html。你应该编辑你的答案并把它贴在那里。一旦你在你的答案中发布它,你可以选择你发布的代码,然后单击{}图标,它将把你的html格式化为代码,这样每个人都可以以更可读的格式看到它。谢谢你的指导。没问题,我已经建立了一个基本的测试环境,我会看看我能找到什么。
<form class="no-widget">
<select name="myFruit">
<option>Cherry</option>
<option>Lemon</option>
<option>Banana</option>
<option>Strawberry</option>
<option>Apple</option>
</select>
<div class="select" role="listbox">
<span class="value">Cherry</span>
<ul id="myList" class="optList hidden" role="presentation">
<li class="option" role="option" aria-selected="true">Cherry</li>
<li class="option" role="option">Lemon</li>
<li class="option" role="option">Banana</li>
<li class="option" role="option">Strawberry</li>
<li class="option" role="option">Apple</li>
</ul>
</div>
</form>
.widget select,
.no-widget .select {
position : absolute;
left : -5000em;
height : 0;
overflow : hidden;
}
/* --------------- */
/* Required Styles */
/* --------------- */
.select {
position: relative;
display : inline-block;
}
.select.active,
.select:focus {
box-shadow: 0 0 3px 1px #227755;
outline: none;
}
.select .optList {
position: absolute;
top : 100%;
left : 0;
}
.select .optList.hidden {
max-height: 0;
visibility: hidden;
}
/* ------------ */
/* Fancy Styles */
/* ------------ */
.select {
font-size : 0.625em; /* 10px */
font-family : Verdana, Arial, sans-serif;
-moz-box-sizing : border-box;
box-sizing : border-box;
padding : 0.1em 2.5em 0.2em 0.5em; /* 1px 25px 2px 5px */
width : 10em; /* 100px */
border : 0.2em solid #000; /* 2px */
border-radius : 0.4em; /* 4px */
box-shadow : 0 0.1em 0.2em rgba(0,0,0,.45); /* 0 1px 2px */
background : #F0F0F0;
background : -webkit-linear-gradient(90deg, #E3E3E3, #fcfcfc 50%, #f0f0f0);
background : linear-gradient(0deg, #E3E3E3, #fcfcfc 50%, #f0f0f0);
}
.select .value {
display : inline-block;
width : 100%;
overflow : hidden;
white-space : nowrap;
text-overflow : ellipsis;
vertical-align: top;
}
.select:after {
content : "▼";
position: absolute;
z-index : 1;
height : 100%;
width : 2em; /* 20px */
top : 0;
right : 0;
padding-top : .1em;
-moz-box-sizing : border-box;
box-sizing : border-box;
text-align : center;
border-left : .2em solid #000;
border-radius: 0 .1em .1em 0;
background-color : #000;
color : #FFF;
}
.select .optList {
z-index : 2;
list-style: none;
margin : 0;
padding: 0;
background: #f0f0f0;
border: .2em solid #000;
border-top-width : .1em;
border-radius: 0 0 .4em .4em;
box-shadow: 0 .2em .4em rgba(0,0,0,.4);
-moz-box-sizing : border-box;
box-sizing : border-box;
min-width : 100%;
max-height: 10em; /* 100px */
overflow-y: auto;
overflow-x: hidden;
}
.select .option {
padding: .2em .3em;
}
.select .highlight {
background: #000;
color: #FFFFFF;
}
// ------- //
// HELPERS //
// ------- //
NodeList.prototype.forEach = function(callback) {
Array.prototype.forEach.call(this, callback);
}
// -------------------- //
// Function definitions //
// -------------------- //
function deactivateSelect(select) {
if (!select.classList.contains('active')) return;
var optList = select.querySelector('.optList');
optList.classList.add('hidden');
select.classList.remove('active');
}
function activeSelect(select, selectList) {
if (select.classList.contains('active')) return;
selectList.forEach(deactivateSelect);
select.classList.add('active');
};
function toggleOptList(select, show) {
var optList = select.querySelector('.optList');
optList.classList.toggle('hidden');
}
function highlightOption(select, option) {
var optionList = select.querySelectorAll('.option');
optionList.forEach(function(other) {
other.classList.remove('highlight');
});
option.classList.add('highlight');
};
function updateValue(select, index) {
var nativeWidget = select.previousElementSibling;
var value = select.querySelector('.value');
var optionList = select.querySelectorAll('.option');
optionList.forEach(function(other) {
other.setAttribute('aria-selected', 'false');
});
optionList[index].setAttribute('aria-selected', 'true');
nativeWidget.selectedIndex = index;
value.innerHTML = optionList[index].innerHTML;
highlightOption(select, optionList[index]);
};
function getIndex(select) {
var nativeWidget = select.previousElementSibling;
return nativeWidget.selectedIndex;
};
// ------------- //
// Event binding //
// ------------- //
window.addEventListener("load", function() {
var form = document.querySelector('form');
form.classList.remove("no-widget");
form.classList.add("widget");
});
window.addEventListener('load', function() {
var selectList = document.querySelectorAll('.select');
selectList.forEach(function(select) {
var optionList = select.querySelectorAll('.option'),
selectedIndex = getIndex(select);
select.tabIndex = 0;
select.previousElementSibling.tabIndex = -1;
updateValue(select, selectedIndex);
optionList.forEach(function(option, index) {
option.addEventListener('mouseover', function() {
highlightOption(select, option);
});
option.addEventListener('click', function(event) {
updateValue(select, index);
});
});
select.addEventListener('click', function(event) {
toggleOptList(select);
});
select.addEventListener('focus', function(event) {
activeSelect(select, selectList);
});
select.addEventListener('blur', function(event) {
deactivateSelect(select);
});
select.addEventListener('keyup', function(event) {
var length = optionList.length,
index = getIndex(select);
if (event.keyCode === 40 && index < length - 1) {
index++;
}
if (event.keyCode === 38 && index > 0) {
index--;
}
updateValue(select, index);
});
});
});
//initialize Sortable
var list = document.getElementById("myList");
Sortable.create(list);