难题:用js如何在客户端上传txt或者xml文件,并能够读取其中的内容到页面上!
难题:用js如何在客户端上传txt或者xml文件,并能够读取其中的内容!不用activex控件,也不再服务端处理!!
------解决方案--------------------FSO+信任站点
------解决方案--------------------HTML
==================
<html>
<head>
<script language= "JavaScript ">
<!--
var i = -1;
var orderDoc = new ActiveXObject( "MSXML2.DOMDocument.3.0 ");
orderDoc.load( "order.xml ");
var items = orderDoc.selectNodes( "/Order/Item ");
function getNode(doc, xpath) {
var retval = " ";
var value = doc.selectSingleNode(xpath);
if (value) retval = value.text;
return retval;
}
function getDataNext() {
i++;
if (i > items.length - 1) i = 0;
document.forms[0].SKU.value = getNode(orderDoc, "/Order/Item[ " + i + "]/SKU ");
document.forms[0].Price.value = getNode(orderDoc, "/Order/Item[ " + i + "]/PricePer ");
document.forms[0].Quantity.value = getNode(orderDoc, "/Order/Item[ " + i + "]/Quantity ");
document.forms[0].Total.value = getNode(orderDoc, "/Order/Item[ " + i + "]/Subtotal ");
document.forms[0].Description.value = getNode(orderDoc, "/Order/Item[ " + i + "]/Description ");
}
function getDataPrev() {
i--;
if (i < 0) i = items.length - 1;
document.forms[0].SKU.value = getNode(orderDoc, "/Order/Item[ " + i + "]/SKU ");
document.forms[0].Price.value = getNode(orderDoc, "/Order/Item[ " + i + "]/PricePer ");
document.forms[0].Quantity.value = getNode(orderDoc, "/Order/Item[ " + i + "]/Quantity ");
document.forms[0].Total.value = getNode(orderDoc, "/Order/Item[ "+ i + "]/Subtotal ");
document.forms[0].Description.value = getNode(orderDoc, "/Order/Item[ " + i + "]/Description ");
}
// -->
</script>
</head>
<body onload= "getDataNext() ">
<h2> XML Order Database </h2>
<form>
<table border= "0 ">
<tr> <td> SKU </td> <td> <input type= "text " name= "SKU "> </td> </tr>
<tr> <td> Price </td> <td> <input type= "text " name= "Price "> </td> </tr>
<tr> <td> Quantity </td> <td> <input type= "text "
name= "Quantity "> </td> </tr>
<tr> <td> Total </td> <td> <input type= "text " name= "Total "> </td> </tr>
<tr> <td> Description </td> <td> <input type= "text "
name= "Description "> </td> </tr>
</table>
<input type= "button " value= " < < " onClick= "getDataPrev(); "> <input type= "button " value= " > > " onClick= "getDataNext(); ">
</form>
</body>
</html>
===========XML
order.xml
=================
<?xml version= "1.0 " ?>
<Order>
<Account> 990