let str = `This is a textwith multiple lines.Escapes are interpreted,\n is a newline.`;let str = String.raw`This is a textwith multiple lines.Escapes are not interpreted,\n is not a newline.`;
var myString = 'A rather long string of English text, an error message \actually that just keeps going and going -- an error \message to make the Energizer bunny blush (right through \those Schwarzenegger shades)! Where was I? Oh yes, \you\'ve got an error and all the extraneous whitespace is \just gravy. Have a nice day.';
var myString = 'A rather long string of English text, an error message ' +'actually that just keeps going and going -- an error ' +'message to make the Energizer bunny blush (right through ' +'those Schwarzenegger shades)! Where was I? Oh yes, ' +'you\'ve got an error and all the extraneous whitespace is ' +'just gravy. Have a nice day.';
<script>
// pure javascriptvar text = document.getElementById("mySoapMessage").innerHTML ;
// using JQuery's document ready for safety$(document).ready(function() {
var text = $("#mySoapMessage").html();
});
</script>
<script id="mySoapMessage" type="text/plain">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="..."><soapenv:Header/><soapenv:Body><typ:getConvocadosElement>...</typ:getConvocadosElement></soapenv:Body></soapenv:Envelope>
<!-- this comment will be present on your string -->//uh-oh, javascript comments... SOAP request will fail
</script>
var new_comment; /*<<<EOF<li class="photobooth-comment"><span class="username"><a href="#">You</a>:</span><span class="comment-text">$text</span>@<span class="comment-time">2d</span> ago</li>EOF*/// note the script tag here is hardcoded as the FIRST tagnew_comment=document.currentScript.innerHTML.split("EOF")[1];document.querySelector("ul").innerHTML=new_comment.replace('$text','This is a dynamically created text');
function s() {var args = [],index;for (index = 0; index< arguments.length; index++) {args.push (arguments [index]);}return args.join ("\n");}console.log (s ("This is the first line","and this is the second","finally a third"));
function s() {return arguments.join ("\n")}
var myString = function(){/*This is someawesome multi-linedstring using a commentinside a functionreturned as a string.Enjoy the jimmy rigged code.*/}.toString().slice(14,-3)
alert(myString)
var c = []; //c stands for contentc.push("<div id='thisDiv' style='left:10px'></div>");c.push("<div onclick='showDo(\'something\');'></div>");$(body).append(c.join('\n'));
var html=<?php echo json_encode("
<div class=container><div class=area1>xxx</div><div class=area2>".$someVar."</div></div>
"); ?>
在你的输出html中,你会看到类似的东西
var html="\r\n\r\n\t\t\t<div class=container>\r\n\t\t\t\t<div class=area1>\r\n\t\t\t\t\txxx\r\n\t\t\t\t<\/div>\r\n\t\t\t\t<div class=area2>\r\n\t\t\t\t\t44\r\n\t\t\t\t<\/div>\r\n\t\t\t<\/div>\r\n\r\n\t\t";
var templates = {myString: `this isa multilinestring`}
alert(templates.myString);
如果您想使用纯JavaScript完成相同的操作:
var templates ={myString: function(){/*This is someawesome multi-linedstring using a commentinside a functionreturned as a string.Enjoy the jimmy rigged code.*/}.toString().slice(14,-3)
}alert(templates.myString)