js输出单一字符字串

<!DOCTYPE HTML>
<html>
<body>
<input type="text" id="str" >
<input type="button" value="click" onclick="test()"> </body>
</html>
<script>
function test(){
//alert("123");
var str = document.getElementById("str").value;
if (str.length <= 1) {
alert(str);
} else {
var maxLen = 0;
var len = 1;
var maxCur = str[0];
var cur = str[0];
for (var i = 0; i < str.length - 1; i++) {
if (str[i] == str[i+1]) {
cur = str[i];
len ++;
} else {
len = 1;
}
if (len > maxLen) {
maxCur = cur;
maxLen = len;
};
}; var strLen = new Array(maxLen+1).join(maxCur);
alert(strLen);
};
}
</script>
上一篇:First step to Signal —— in Linux C Programing


下一篇:SQL——按照季度,固定时间段,分组统计数据