Qua*_*ess 0 javascript jquery filesystemobject activexobject fso
例如:
var a = " ";
var b = "";
b = a * 8;
alert(b +"this far to the right");
Run Code Online (Sandbox Code Playgroud)
注意:我不想使用,因为ActiveX FSO将用于写入文本文件而不是html文件.所以它只需要空格:
我正在努力实现的更详尽的细节:
我试图让ActiveX FSO在提交表单后从HTML订单表单写入文本文件,然后继续将订单写入文本文件.文本文件需要采用特定格式,以便Microsoft Dynamics接受作为导入销售.
如下所示:客户代码 空间 商品代码 空间 数量 空间:
import.txt减去字符串长度,其中slot =要填充的剩余空格.
C242299A *4 white spaces* 2890 *12 white spaces* 20 *6 white spaces*
[------------][----------------][--------]
12 char slots 16 char slots 8 char slots
Run Code Online (Sandbox Code Playgroud)
write.js将创建这个import.txt文件(这是我需要帮助的部分)
var customercode = document.getElementById("customercode").value;
var itemcode = document.getElementById("itemcode").value;
var quantity = document.getElementById("quantity").value;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile(path+"import.txt",8,true,0);
//customer code string length must be measured to determine remaining spaces
//to fill before item code can be entered.
//you only have 12 character slots before the next string "item code" can be entered
var remainingSpaces = "";
remainingSpaces = 12 - customercode.length;
spacefill1 = " " * remainingspaces;
remainingSpaces = 16 - itemcode.length;
spacefill2 = " " * remainingSpaces;
remainingSpaces = 8 - quantity.length;
spacefill3 = " " * remainingSpaces;
s.WriteLine(customercode+spacefill1+itemcode+spacefill2+quantity+spacefill3);
Run Code Online (Sandbox Code Playgroud)
假设创建一个如下所示的文本文件:
C242299A 2890 20
Run Code Online (Sandbox Code Playgroud)
然后将导入到Microsoft Dynamics.
但问题是它不会将空间视为0/null的空间乘以:( 欢迎使用Jquery解决方案.
要多次重复某个字符,请使用:
var max = 8;//times to repeat
var chr = "a";//char to repeat
console.log(new Array(max + 1).join(chr));//aaaaaaaa
Run Code Online (Sandbox Code Playgroud)
请注意,如果使用空格执行此操作,它们通常会压缩成一个空格(但它们在那里).
您可以使用<pre>
标记显示每个单独的空白区域(演示)
归档时间: |
|
查看次数: |
1312 次 |
最近记录: |