日期:2014-05-16 浏览次数:20368 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">哪儿有错啊?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function toNewStr(str, index) {
var st = '',strarr;
strarr = str.split("<br/>");
for(var i=0; i<strarr.length; i++) {
if(index<strarr[i].length && index==strarr[i].length)
return st += strarr[i].substr(0, index);
else
return str += toNewStr(strarr[i+1], index-strarr[i].length) + '<br />';
}
}
var str='abc一二三<br/>一二三';
var s = toNewStr('abc一二三<br/>一二三',8);
alert(s);
</script>
</head>
<body>
</body>
</html>
if(index<strarr[i].length && index==strarr[i].length)