同事日常工作用到的一个小功能,需要把一串数字排序并让他能复制出来。
效果如下: html部分
<input type="text" id="a">
<button id="b">排序</button>
<div id="c"></div>
js部分
var a
= document
.getElementById('a');
var b
= document
.getElementById('b');
var c
= document
.getElementById('c');
b
.onclick = function() {
var d
= a
.value
.split(' ').sort(function(x
, y
) {
return x
- y
;
});
d
= d
.join(" ")
c
.innerHTML
= d
;
}