<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<form name="form1">
<p>请输入一组数据:
<input type="text" name="textfield" id="textfield" />
</p>
<p>
<input type="button" name="button1" id="button1" value="提交" onclick="add()" />
<input type="button" name="button3" id="button3" value="显示" onclick="xianshi()" />
<input type="button" name="button2" id="button2" value="排序" onclick="xspaixu()" />
</p>
<p>
<textarea name="textarea" id="wby" cols="45" rows="5"></textarea>
</p>
</form><script type="text/javascript">
var arrData = [];
function add(){
arrData.push(document.getElementById("textfield").value);
}
function xianshi(){
document.getElementById("wby").value = arrData.join(',');
}
function xspaixu(){
var el = document.getElementById("wby");
var arr = el.value.split(",");
for(var i = 0 ; i<arr.length ; i++){
arr[i] = parseFloat(arr[i]);
}
el.value = arr.sort().join(',')
alert("排序成功");
}
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<form name="form1">
<p>请输入一组数据:
<input type="text" name="textfield" id="textfield" />
</p>
<p>
<input type="button" name="button1" id="button1" value="提交" onclick="add()" />
<input type="button" name="button3" id="button3" value="显示" onclick="xianshi()" />
<input type="button" name="button2" id="button2" value="排序" onclick="xspaixu()" />
</p>
<p>
<textarea name="textarea" id="wby" cols="45" rows="5"></textarea>
</p>
</form><script type="text/javascript">
var arrData = [];
function add(){
arrData.push(document.getElementById("textfield").value);
}
function xianshi(){
document.getElementById("wby").value = arrData.join(',');
}
function xspaixu(){
var el = document.getElementById("wby");
var arr = el.value.split(",");
for(var i = 0 ; i<arr.length ; i++){
arr[i] = parseFloat(arr[i]);
}
el.value = arr.sort().join(',')
alert("排序成功");
}
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form name="form1">
<p>请输入一组数据:
<input type="text" name="textfield" id="textfield" />
</p>
<p>
<input type="button" name="button1" id="button1" value="提交" onclick="add()" />
<input type="button" name="button3" id="button3" value="显示" onclick="xianshi()" />
<input type="button" name="button2" id="button2" value="排序" onclick="xspaixu()" />
</p>
<p>
<textarea name="textarea" id="wby" cols="45" rows="5"></textarea>
</p>
</form>
<script type="text/javascript">
var arrData = [];
function add(){
arrData.push(document.getElementById("textfield").value);
}
function xianshi(){
document.getElementById("wby").value = arrData.join(',');
}
function xspaixu(){
var el = document.getElementById("wby");
var arr = el.value.split(",");
for(var i = 0 ; i<arr.length ; i++){
arr[i] = parseFloat(arr[i]);
}
el.value = sort(arr).join(',')
alert("排序成功");
}
function sort(a){
for(var i=0;i<a.length;i++){
for(var j=i+1;j<a.length;j++){
if(a[i]>a[j]){
var temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}}
return a
}
</script>
</body>
</html>