我有一个像12k4353535352311
这样的序列号,我希望使用JavaScript来实现如下:
12k4-35353535-2311
我试过这个,但我觉得它没用了
$('#dev_serial').change(function(){
//var serial = $('#dev_serial').val();
var number =$('#dev_serial').val();
output = [],
sNumber = number.toString();
alert(output);
/* Outputs:
*
* [1, 2, 3, 5, 4, 9, 8, 7]
*/
//var series = (''+serial)[1];
});
答案 0 :(得分:1)
<script>
var key = "12k4353535352311";
var res = key.substring(0,4)+'-'+key.substring(4,12)+'-'+key.substring(12,16); //This contains 12k4-35353535-2311
</script>