我正在尝试使用JavaScript函数在我的网站上获得一些ASCII艺术作品,但结果不是我现在正在寻找的东西...
这是它的外观:
这是我用来尝试实现的代码:
function log( text ) {
$log = $('#log');
//Add text to log
$log.append(($log.val()?"":'')+ text );
//Autoscroll
$log[0].scrollTop = $log[0].scrollHeight - $log[0].clientHeight;
}
log('<div style="font-family: monospace; white-space: pre;">' +
" _______ <br>" +
" |__ __| <br>" +
" | | ___ _ __ ___ _ __ ___ _ _ <br>" +
" | |/ _ \| '_ ` _ \| '_ ` _ \| | | |<br>" +
" | | (_) | | | | | | | | | | | |_| |<br>" +
" |_|\___/|_| |_| |_|_| |_| |_|\__, |<br>" +
" __/ |<br>" +
" |___/ <br>" +
"<br>" +
"</div>");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="log"></div>
希望你们能得到比我更好的结果,因为这对我现在根本行不通。
最佳答案
您必须注意,如果要打印'\'字符,则必须在字符串中使用'\\'代替:)
function log( text ) {
$log = $('#log');
//Add text to log
$log.append(($log.val()?"":'')+ text );
//Autoscroll
$log[0].scrollTop = $log[0].scrollHeight - $log[0].clientHeight;
}
log('<div style="font-family: monospace; white-space: pre;">' +
" _______ <br>" +
" |__ __| <br>" +
" | | ___ _ __ ___ _ __ ___ _ _ <br>" +
" | |/ _ \\| '_ ` _ \\| '_ ` _ \\| | | |<br>" +
" | | (_) | | | | | | | | | | | |_| |<br>" +
" |_|\\___/|_| |_| |_|_| |_| |_|\\__, |<br>" +
" __/ |<br>" +
" |___/ <br>" +
"<br>" +
"</div>");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="log"></div>