<! DOCTYPE html>
Css.css
div { width:800px; height:200px; Background: #f1f1f1; margin:0 Auto; Text-align:center; line-height:20px; border:1px solid #ccc; border-radius:10px;} h2 { font-size:20px; width:100%;} button { cursor:pointer; Background: #eee; border:1px solid #ddd;} input { width:165px; height:25px; border:1px solid #ddd;}
Js.js
Window.onload = function () {var obtn = document.getelementsbytagname ("button"); var oipt = document.getelementsbytagname ("input"); Obtn[0].onclick = function () {var str = oipt[0].value; var Objchar = {}; for (var i = 0; i < str.length; i++) {var char = Str.charat (i); if (Objchar[char]) {Objchar[char] + = 1; } else {Objchar[char] = 1; }} var maxCount = 0; var maxcharindex = []; for (var key in Objchar) {if (MaxCount < Objchar[key]) {maxCount = Objchar[key]; Maxcharindex = []; Maxcharindex.push (key); } else if (MaxCount = = Objchar[key]) {Maxcharindex.push (key); }} function GetCount () {return maxCount; } function Getmaxchar () {return maxcharindex; } var objindex = {}; var maxindex= []; for (var j = 0; J < Maxcharindex.length, J + +) {for (var i = 0; i < str.length; i++) {if (Str[i] = = Maxcharindex[j]) {Maxindex.push (i); } if (i = = str.length-1) {Objindex[maxcharindex[j]] = Maxindex; Maxindex = []; }}} function GetIndex () {var maxIndex2 = []; for (var key in Objindex) {Maxindex2.push (key +) is indexed ("+ Objindex[key] +") "; } return MAXINDEX2; } Oipt[1].value = GetCount (); Oipt[2].value = Getmaxchar (); Oipt[3].value = GetIndex (); }}
Search for the maximum number of occurrences of a character in a string, the most frequently occurring character, and the index of the character with the most occurrences