Javascript中作为函数参数的新行字符
从Test.html中,我包括一个运行函数d()的Test.js。此函数有一个参数a字符串,该字符串可能包含“新行”字符(ASCII中的10),如下例所示。但是,当我调试此函数时,varss和data包含除新行以外的所有字符,即它们包含字符串“HelloWorld”(长度10),而不是“Hello[charNewLine]World”(长度11) 有没有一种方法可以将带有新行字符的字符串作为参数传递给Javascript中的函数?多谢各位 Test.htmlJavascript中作为函数参数的新行字符,javascript,parameters,character-encoding,ascii,Javascript,Parameters,Character Encoding,Ascii,从Test.html中,我包括一个运行函数d()的Test.js。此函数有一个参数a字符串,该字符串可能包含“新行”字符(ASCII中的10),如下例所示。但是,当我调试此函数时,varss和data包含除新行以外的所有字符,即它们包含字符串“HelloWorld”(长度10),而不是“Hello[charNewLine]World”(长度11) 有没有一种方法可以将带有新行字符的字符串作为参数传递给Javascript中的函数?多谢各位 Test.html <html> <h
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=x-user-defined">
<title>JavaScript Scripting</title>
</head>
<body>
<script type="text/javascript" charset="x-user-defined" src="test.js">
</script>
</body>
</html>
JavaScript脚本
test.js
function d(s)
{
var data = (s + "").split("");
var dataLength = data.length;
var t = [dataLength],n;
for(n=0;n<dataLength;n++)
t[n]=data[n].charCodeAt(0);
}
d("Hello\
World");
功能d(s)
{
变量数据=(s+“”)。拆分(“”);
var dataLength=data.length;
var t=[dataLength],n;
对于(n=0;n
包含“行延续”
警察说
文字的字符串值(SV)是根据字符串文字的各个部分提供的字符值(CV)来描述的
LineContinuation::\LineTerminatorSequence
的SV是空字符序列
这意味着它不会为字符串文本的值提供任何字符
要在字符串中嵌入换行符,只需使用中的\n
d("Hello\nWorld")
如果要查看新行并在字符串中传递它,请按以下方式使用:
d("Hello\n\
World");
d("Hello\n\
World");