作者:育霖培伦861 | 来源:互联网 | 2022-03-11 19:01
代码如下:
代码如下:
function ObjRegExp(){
var newStr= "Drive someone up a wall";
newStr = newStr.replace(new RegExp(/\s/ig),"");
var objJson = {};
for(var i = 0 ;i var objChar = newStr.charAt(i);
if(objJson[objChar]){
objJson[objChar] = parseInt(objJson[objChar]) + 1;
}else{
objJson[objChar] = 1;
}
}
var oDiv = document.getElementById("objDiv");
oDiv.appendChild(document.createTextNode("Drive someone up a wall!"));
oDiv.appendChild(document.createElement("
"));
for(var key in objJson){
oDiv.appendChild(document.createTextNode(key +":"+ objJson[key]));
oDiv.appendChild(document.createElement("
"));
}
}
Html 如下:
代码如下: