当我尝试将包含多行的字符串写入输出文本文件时,不会保留换行符,并且所有内容都打印在一行中.
具体来说,我有一个按钮,点击一个监听器并关联此功能:
function (e) {
this.downloadButton.setAttribute("download", "output.txt");
var textToSend = string1+"\r\n"+string2+"\r\n"+string3;
this.downloadButton.setAttribute('href', 'data:text/plain;charset=utf-8,' + textToSend);
}
Run Code Online (Sandbox Code Playgroud)
文件正确下载,但string1,string2和string3在同一行.
有什么建议吗?
如何从 objectReference["functionName"] 形式的输入中检索对包含函数的对象的引用。
例子:
function aaa(param) {
var objectReference = /*..???...*/;
var functionName = /*...???..*/;
// Now expected result is that objectReference contains
// a reference to myObject, and functionName contains a
// string with name of function (implemented in myObject),
// so I can invoke it with objectReference[functionName]()
// after some manipulation.
}
var myObject = new SomeFunction();
aaa(myObject["myFunction"]);
Run Code Online (Sandbox Code Playgroud)
谢谢