我尝试使用 Javascript 创建 CSV 文件下载。
\n\n我们需要将数据从我们的网站导出到第三方程序,创建和下载效果很好。只有一个问题,我需要以 ANSI (Windows-1252) 编码的 CSV 文件 - 第 3 方程序非常旧,无法理解多字节编码。我的文件以 UTF-8 格式提供,到目前为止我还没有找到将文件转换为 ANSI 的方法,我总是得到 UTF-8-Content...
\n\n当前的修补程序是打开文件并手动将编码更改为 ANSI,但这并不好,而且对于我公司中的一些人来说很难做到(有时他们会忘记它,因为他们对 PC 不太熟悉)。
\n\n我想要一个可以在 ANSI 格式(而不是 UTF-8 格式)中使用的文件。我可以用 PHP 转换文件,它具有正确的编码和内容,但我在服务器上没有写访问权限,这就是为什么我需要使用 AJAX 动态下载文件。
\n\n我在 Stackoverflow 上使用了像他这样的解决方案:/sf/answers/1546258381/
\n\n但我得到 UTF-8 作为内容。
\n\n我退后一步,尝试在一个非常简单的页面上使用 JavaScript 进行转换,但我也得到了 UTF-8...:
\n\n<html>\n <head>\n <meta http-equiv="Content-Type" content="text/html" charset="utf-8" />\n <title>My File-Download</title>\n <script type=\'text/javascript\' src=\'encoding.js\'></script>\n <script type=\'text/javascript\' src=\'encoding-indexes.js\'></script>\n <script type=\'text/javascript\' src=\'FileSaver.min.js\'></script>\n <script type=\'text/javascript\'>\n <!--\n\n /**\n * Downloads the Text as File\n *\n …Run Code Online (Sandbox Code Playgroud) 我有一个document.write()用于写入页面的JavaScript函数.我的问题是,当我单击按钮调用该函数时,document.write()将我已经拥有的内容替换为我正在编写的内容.有没有办法从JavaScript写一个特定的div文本?
这是我的HTML代码:
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="javascript.js">
</script>
<script>
// Calling the Google Maps API
</script>
<script>
<!-- JavaScript to load Google Maps -->
</script>
</head>
<body>
<div class="content">
<div id="googleMap"></div>
<div id="right_pane_results">hi</div>this -->
<div id="bottom_pane_options">
<button onclick="todaydate();">Try It</button>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
...和我的JavaScript代码(我从互联网上获得的东西只是为了测试):
function todaydate() {
var today_date = new Date();
var myyear = today_date.getYear();
var mymonth = today_date.getMonth() + 1;
var mytoday = today_date.getDate();
document.write("<h1>" + myyear + "/" + mymonth …Run Code Online (Sandbox Code Playgroud)