javascript 字符串中间隔固定位置插入字符
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title</title>
<script src="jquery-3.1.0.js"></script> <!--引入jquery-->
</head>
<body>
<script>
function str_insert_str( //字符串插入字符串
str, //原字符串
sub_length, //隔几个字符插入
insert_str //要插入的字符
) {
var insert_len = insert_str.length; //插入字符串的长度
var sub_count = Math.floor(str.length / sub_length) //地板除
// console.log("地板除:", sub_count);
if (sub_count > 0) {
for (var i = 0; i < sub_count; i++) {
console.log("i * sub_length + sub_length + i:", i * sub_len