本文介绍了我该如何创建一个新行或向此Javascript函数添加HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我尝试了所有三种方法:一种是打印机,一种是打印机,另一种是打印机, \\\ \ $ < br />> 但只是输入这些字符。 这是我的javascript函数: $ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $这个 defaults = {animDelay:50}, settings = $ .extend(defaults,opts); $ .each(settings.text,function(i,letter){ setTimeout(function(){ $ this.html($ this.html()+ letter); },settings.animDelay * i); }); } 以下是我称之为的示例: $('#howto')。Typewriter({ animDelay:100, text:'Lorem ipsum dolor sit amet ,consectetur adipisicing elit,< br / gt; sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。\r Ut enim ad minim veniam,quis nostrud practitation \\\ ullamco laboris nisi ut aliquiqu ex ea commodo consequat。'} ); 这就是它最终的样子: Lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam,quis nostrud practitation ullamco laboris nisi ut aliquip ex ea大宗商品的后代。 我希望它看起来像: Lorem ipsum dolor sit amet,consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。 不可以登录,也可以尝试使用 ullamco laboris nisi ut aliquip ex ea commodo consequat。 所有帮助表示感谢! http://jsfiddle.net/9Qsku/ 解决方案在字符串上使用\\\,并以此方式修改snipplet $。fn .Typewriter = function(opts){ var $ this = this, defaults = {animDelay:50}, settings = $ .extend(defaults,opts); $ .each(settings.text,function(i,letter){ setTimeout(function(){ $ this.html($ this.html()+(letter!=' \\\'?letter:'< br />')); },settings.animDelay * i); }); } I trying to create a typewriter effect, I got everything working, but I cannot figure out how to create a new line.I've tried all three:\n\r<br />but it just types those characters.Here is my javascript function:$.fn.Typewriter = function(opts){ var $this = this, defaults = { animDelay: 50 }, settings = $.extend(defaults, opts); $.each(settings.text, function(i, letter){ setTimeout(function(){ $this.html($this.html() + letter); }, settings.animDelay * i); });}Here is an example how I'm calling it:$('#howto').Typewriter({animDelay: 100,text: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, <br /> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \r Ut enim ad minim veniam, quis nostrud exercitation \n ullamco laboris nisi ut aliquip ex ea commodo consequat.'});This is how it end up looking:"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."I want it to look like:Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitationullamco laboris nisi ut aliquip ex ea commodo consequat.All help is appreciated!http://jsfiddle.net/9Qsku/ 解决方案 use \n on the string and the snipplet modified this way$.fn.Typewriter = function(opts){var $this = this, defaults = { animDelay: 50 }, settings = $.extend(defaults, opts);$.each(settings.text, function(i, letter){ setTimeout(function(){ $this.html($this.html() + (letter!='\n'?letter:'<br />')); }, settings.animDelay * i);});} 这篇关于我该如何创建一个新行或向此Javascript函数添加HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-10 20:19