嘿有一些“简单”的文本替换问题......有一个 html 页面,想用二维字段做一些简单的替换
函数“createArray”没有类似问题的答案,但我无法让它工作:
<script type="text/javascript">
function createArray(length) {
var arr = new Array(length || 0),
i = length;
if (arguments.length > 1) {
var args = Array.prototype.slice.call(arguments, 1);
while(i--) arr[length-1 - i] = createArray.apply(this, args);
}
return arr;
}
window.onload = function(){
var tabelle = createArray(14, 2);
tabelle[0][0]="Comment:Header"; tabelle[0][1]="test";
tabelle[1][0]="Comment:Lane"; tabelle[1][1]=" ";
tabelle[2][0]="Comment:VS"; tabelle[2][1]=" ";
tabelle[3][0]="Comment:Early1"; tabelle[3][1]=" ";
tabelle[4][0]="Comment:Early2"; tabelle[4][1]=" ";
tabelle[5][0]="Comment:Early3"; tabelle[5][1]=" ";
tabelle[6][0]="Comment:Mid1"; tabelle[6][1]=" ";
tabelle[7][0]="Comment:Mid2"; tabelle[7][1]=" ";
tabelle[8][0]="Comment:Mid3"; tabelle[8][1]=" ";
tabelle[9][0]="Comment:Late1"; tabelle[9][1]=" ";
tabelle[10][0]="Comment:Late2"; tabelle[10][1]=" ";
tabelle[11][0]="Comment:Late3"; tabelle[11][1]=" ";
tabelle[12][0]="Comment:etc1"; tabelle[12][1]=" ";
tabelle[13][0]="Comment:etc2"; tabelle[13][1]=" ";
for (var i = 0; i < tabelle.length; i++)
document.body.innerHTML =
document.body.innerHTML.replace(tabelle[i][0], tabelle[i][1]);
};
</script>
thx 已经 ;D
编辑:http: //jsfiddle.net/kF7kg/