pred$mean
我想打印下一行中的每个句子作为一首诗......!但如果有人愿意提供帮助,我就不能这样做。我会欣赏他/她 在此先感谢
答案 0 :(得分:1)
使用您自己的旗帜,例如char"#" 。 我在索引处使用简单检查char并使用标签br /。 更好的解决方案是使用char"?"换新线。请参阅代码段示例2。
<center><p id="demo" style="color:black;"></p></center>
<script>
window.onload = function() {
typeWriter();
};
var i =0;
var txt = "Would it be ok if I wrote you a rhyme?# would it be ok if I opened my heart? # Would it be ok if I took on the part Of being your man and showed you a view, One that only a real man could do?# Would it be ok if I could make you smile?# Would it be alright to look in your eyes? Would it be alright to never tell lies?# Would it be alright to find a way?# Would it be alright to long for the day To pull you close and whisper in your ear And tell you our feelings are nothing to fear? Would it be ok if I took some of your time?# Would it be ok if I wrote you a rhyme?# To tell you there is nothing I would rather do Than spend my whole life loving only you... ";
var txt1= '';
var speed = 100;
function typeWriter() {
if (i < txt.length) {
if (txt.charAt(i) == "#"){
document.getElementById("demo").innerHTML += "<br/>";
}
else {
document.getElementById("demo").innerHTML += txt.charAt(i);
}
document.getElementById("demo").innerHTML += txt1.charAt(i);
i++;
setTimeout(typeWriter, speed);
}
}
</script>
&#13;
示例2:
<center><p id="demo" style="color:black;"></p></center>
<script>
window.onload = function() {
typeWriter();
};
var i =0;
var txt = "Would it be ok if I wrote you a rhyme? would it be ok if I opened my heart? Would it be ok if I took on the part Of being your man and showed you a view, One that only a real man could do? Would it be ok if I could make you smile? Would it be alright to look in your eyes? Would it be alright to never tell lies?Would it be alright to find a way? Would it be alright to long for the day To pull you close and whisper in your ear And tell you our feelings are nothing to fear? Would it be ok if I took some of your time? Would it be ok if I wrote you a rhyme? To tell you there is nothing I would rather do Than spend my whole life loving only you... ";
var txt1= '';
var speed = 100;
function typeWriter() {
if (i < txt.length) {
if (txt.charAt(i) == "?"){
document.getElementById("demo").innerHTML += txt.charAt(i);
document.getElementById("demo").innerHTML += "<br/>";
}
else {
document.getElementById("demo").innerHTML += txt.charAt(i);
}
document.getElementById("demo").innerHTML += txt1.charAt(i);
i++;
setTimeout(typeWriter, speed);
}
}
</script>
&#13;
粗体(小解析器)示例: 这有点复杂。我们需要动态创建元素和append方法也是一个FLAG。
<center><p id="demo" style="color:black;"></p></center>
<script>
window.onload = function() {
typeWriter();
};
var i =0;
var txt = "Would it be ok if I wrote you a #rhyme#? would it be ok if I opened my #heart#? Would it be ok if I took on the part Of being your man and showed you a view, One that only a real man could do? Would it be ok if I could make you smile? Would it be alright to look in your eyes? Would it be alright to never tell lies?Would it be alright to find a way? Would it be alright to long for the day To pull you close and whisper in your ear And tell you our feelings are nothing to fear? Would it be ok if I took some of your time? Would it be ok if I wrote you a rhyme? To tell you there is nothing I would rather do Than spend my whole life loving only you... ";
var txt1= '';
var speed = 100;
var BOLD_ELE = null;
var isBold = false;
function typeWriter() {
if (i < txt.length) {
if (isBold == true ){
var BOLD_ELE = document.createElement('B');
document.getElementById("demo").appendChild(BOLD_ELE);
}
if (txt.charAt(i) == "?"){
document.getElementById("demo").innerHTML += txt.charAt(i);
document.getElementById("demo").innerHTML += "<br/>";
}
else if (txt.charAt(i) == "#"){
if (isBold == false) {
isBold = true
}
else {
isBold = false
}
}
else {
if (isBold == false){
document.getElementById("demo").innerHTML += txt.charAt(i);
}
else {
BOLD_ELE.innerHTML += txt.charAt(i);
}
}
document.getElementById("demo").innerHTML += txt1.charAt(i);
i++;
setTimeout(typeWriter, speed);
}
}
</script>
&#13;