发布网友 发布时间:2022-04-24 05:58
共3个回答
热心网友 时间:2022-04-23 06:08
<!DOCTYPE HTML>
<html>
<head>
<title>念奴娇</title>
<meta charset=UTF-8 />
<style type="text/css">
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
onload = function ()
{
var array = "";
while (!/^\s*([\+\-]?((\d+(\.\d*)?)|(\d*\.\d+))\s*\,\s*)*[\+\-]?((\d+(\.\d*)?)|(\d*\.\d+))\s*$/.test (array = prompt ("输入数字,英文逗号隔开", "")))
{
alert ("含有非法数字, 重新输入!");
}
array = array.split (",");
for ( var i = 0; i < array.length; i++)
{
for ( var j = i + 1; j < array.length; j++)
{
if (parseFloat (array[i], 10) > parseFloat (array[j], 10))
{
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
document.write ("从小到大的冒泡排序:" + array.join (","));
}
</script>
</head>
<body>
</body>
</html>
热心网友 时间:2022-04-23 07:26
var arr = [1,3,2],
arr2 = [1,'g','s'];
function validArr(arr) {
var isNumArr = true,
i = 0,
len = arr.length;
for(; i < len; i++) {
if(!parseInt(arr[i], 10)) {
isNumArr = false;
break;
}
}
return isNumArr;
}
function sortNumber(a, b) {
return a-b;
}
function show(ar) {
var boo = validArr(ar);
if(boo) {
console.log(ar.sort(sortNumber));
}else {
console.log('this arr isn\'t all num');
}
}
show(arr);
show(arr2);
热心网友 时间:2022-04-23 09:00
var obj="xxxxxxxxxxx";
if(isNaN(parseInt(obj)));//判断是否纯数字
{
for(var i=0;i<obj.length;i++)
{
for(var j=0;j<obj.length;j++)
{
if(obj[i]>obj[j])
{
var count;
count=obj[i];
obj[i]=obj[j];
obj[j]=count;
}
}
}
alert(obj)
}