javascpt语言,三个整数运用input输入以后排序,排序结果还在input里面怎么实现

javascpt语言,三个整数运用input输入以后排序,排序结果还在input里面怎么实现
请解答详细一些,磕头拜谢

<input type="text" onblur="this.value = this.value.match(/\d+/g).sort(function (a, b) { return a - b }).join(' ')" />

Problem Description
输入三个整数x,y,z,请把这三个数由小到大输出。
Input
输入数据包含3个整数x,y,z,分别用逗号隔开。
Output
输出由小到大排序后的结果,用空格隔开。
Example Input
2,1,3
Example Output
1 2 3

#include
int main()
{
int a,b,c,t;
scanf("%d,%d,%d",&a,&b,&c);
if(a>b)
{t=a;a=b;b=t;}
if(a>c)
{t=a;a=c;c=t;}
if(b>c)
{t=b;b=c;c=t;}
printf("%d %d %d",a,b,c);
return 0;

}

作者:呃奥哦
来源:CSDN
原文:https://blog.csdn.net/be_your_back/article/details/52902218
版权声明:本文为博主原创文章,转载请附上博文链接!

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>sort</title>
</head>
<body>
<input type="text" placeholder="数字用逗号分割" /><button onclick="sort()">排序</button>   
</body>
<script>
function sort(){
    var el = document.querySelector('input');
    var vals = el.value.replace(/[^,\d]/g, '').replace(/(^,|,$)/g, '').split(',');
    vals.sort(function (a,b){
        return parseFloat(a) > parseFloat(b);
    });
    el.value = vals.join(',');
}
</script>
</html>