日期:2014-05-16 浏览次数:20562 次
var txt = 'This is some sample text. Select this text.' ;
var ins = "AAA"
var txt_ins = 'This is AAA some sample text. Select this text.' ;
var txt_ins = 'This is AAA some AAA sample text. Select this text.' ;
var txt_ins = 'This AAA is AAA some AAA sample text. Select this text.' ;
function getNewInsertIndex(oldArray,newArray){
if(oldArray.length==newArray.length)alert('没有找到或者插入新内容!');
else{
var index=0;
for(var i=0,j=newArray.length;i<j;i++){
index+=newArray[i].length
if(newArray[i]!=oldArray[i]){index+=i*ins.length;/*加上分隔字符长度*/ alert('新插入的内容位置为'+index);break;}
}
}
}
var txt = 'This is some sample text. Select this text.' ;
var ins = "AAA "
var txt_ins = 'This is AAA some sample text. Select this text.' ;
var arr=[],newarr=txt_ins.split(ins);
getNewInsertIndex(arr,newarr);
arr=newarr;//交换位置,每次更新过内容后记得交换位置
txt_ins ='This AAA is AAA some sample text. Select this text.' ;
newarr=txt_ins.split(ins)
getNewInsertIndex(arr,newarr)
arr=newarr;//
txt_ins ='AAA This AAA is AAA some sample text. Select this text.'
newarr=txt_ins.split(ins)
getNewInsertIndex(arr,newarr)
arr=newarr;//
txt_ins ='AAA This AAA is AAA some sample text. AAA Select this text.'
newarr=txt_ins.split(ins)
getNewInsertIndex(arr,newarr)
arr=newarr;//
txt_ins ='AAA This AAA is AAA some sample text. AAA Select this AAA text.'
newarr=txt_ins.split(ins)
getNewInsertIndex(arr,newarr)
arr=newarr;//
txt_ins ='AAA This AAA is AAA some sample text. AAA Select this AAA text AAA .'
newarr=txt_ins.split(ins)
getNewInsertIndex(arr,newarr)
arr=newarr;//