div内的中英文字符串换行问题
用HTML加javascript实现打字机样的效果…当字符串为英文时无法自动换行…中文时可以自动换行
<?xml version="1.0" encoding="utf-8" ?>
<!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> test typing </title>
<script type="text/javascript" src="js/temp.js">
</script>
</head>
<body>
<div id="myDiv" style="width:200px; height:100px; border:2px #ccc dashed; padding:10px"></div>
<script>
var typingText = "abcdefghijklmnopqrstuvwxyzwhy中文字符可以自动换行不会超过边框";
var count = 0;
var myBlock = document.getElementById("myDiv");
function type(){
if(count <= typingText.length){
myBlock.innerHTML = typingText.substring(0, count);
count++;
}else{
window.clearInterval(intervalID);
}
}
var intervalID = window.setInterval(type, 200);
</script>
</body>
</html>