<HTML>
<HEAD>
<TITLE>javascript打印-打印页面设置-打印预览-保存代码</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312" />
<SCRIPT language=javascript>
function printsetup() {
// 打印页面设置
wb.execwb(8,1);
}
function printpreview() {
// 打印页面预览
wb.execwb(7,1);
}
function printit() {
if (confirm('确定打印吗?')) {
wb.execwb(6,6)
}
}
function $(str)
{
return document.getElementById(str);
}
function RWFile(){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
if(!xmlDoc.load("C:\\test.xml")){
xmlDoc.appendChild(xmlDoc.createElement("root"));
//xmlDoc.insertBefore(xmlDoc.createProcessingInstruction("xml","version='1.0'"),xmlDoc.firstChild);
}
var xname=xmlDoc.createElement("name");
xname.text=$("name").innerHTML;
var xprice=xmlDoc.createElement("price");
xprice.text=$("price").innerHTML;
var xpair=xmlDoc.createElement("pair");
xpair.appendChild(xname);
xpair.appendChild(xprice);
xmlDoc.getElementsByTagName("root")[0].appendChild(xpair);
var fso=new ActiveXObject("Scripting.FileSystemObject");
rFile=fso.CreateTextFile("C:\\test.xml",1,true);
rFile.WriteLine('<?xml version="1.0"?>');
rFile.WriteLine(xmlDoc.documentElement.xml);
rFile.close();
//xmlDoc.save("C:\\u.xml");
}
function RDFile(){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
if(!xmlDoc.load("C:\\test.xml")){
$("result").innerHTML="没有记录!";
return;
}
var xpair=xmlDoc.getElementsByTagName("pair");
if(xpair.length==0){
$("result").innerHTML="没有记录!";
return;
}
$("result").innerHTML=""
for(var i=0;i<xpair.length;i++)$("result").innerHTML+="姓名:"+xpair[i].firstChild.text+" 金额:"+xpair[i].lastChild.text+"<br />";
}
</SCRIPT>
</HEAD>
<BODY>
<DIV>
<OBJECT id=wb height=0 width=0
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT>
<INPUT οnclick=javascript:printit() type=button value=打印
name=button_print />
<INPUT οnclick=javascript:printsetup(); type=button value=打印页面设置
name=button_setup />
<INPUT οnclick=javascript:printpreview(); type=button value=打印预览
name=button_show />
<button οnclick='document.execCommand("saveAs")'>另存为...</button>
</DIV><br><br>
<form id="form1" runat="server">
<tr><td width="56" ><strong>姓 名:<br></strong></td></tr>
<div contenteditable="true" id="name" style="width: 200px; height: 20px; border: 1px;
border-color: Green; border-style: solid"></div>
<tr> <td width="56" ><strong>金 额:</strong></td></tr>
<div contenteditable="true" id="price" style="width: 200px; height: 20px; border: 1px;
border-color: Green; border-style: solid"></div>
<input type="button" value="写入记录" οnclick="RWFile()" /> <input type="button" value="读取记录" onClick="RDFile()" />
</form>
<div id="result"></div>
</BODY>
</HTML>