我正在尝试使用一个简单的 jquery 打字机来识别像 \n 和 \r 这样的空白字符,以便生成的文本实际上会有换行符。当我尝试让控制结构识别“\”时,根本没有运行...任何帮助表示赞赏!
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var text = "runtype";
var count = 0;
var maxspeed = 200;
$(document).ready(function() {
function typeit(userInput) {
text = userInput;
type();
}
function character(start, end, text) {
return text.substring(start, end);
}
function type(){
var random = Math.floor(Math.random() * maxspeed);
var char1 = character(count, count+1, text);
var char2 = character(count+1, count+2, text);
var whitespace = char1+char2;
if (char1 === '\\'){
$('#box').append(whitespace);
setTimeout(type, 20);
} else if (char1 === ' '){
$('#box').append(char1);
setTimeout(type, 20);
}else if (char1 === '@'){
;
setTimeout(type, 300);
} else {
$('#box').append(char1);
setTimeout(type, random);
}
count++;
}
typeit('runtype and \\nruntype and runtype');
});
</script>
</head>
<body>
<div id="box"></div>
</body>
</html>