尝试使用“ OpenFile”功能打开创建的记事本文件(通过我的SubmitOrder函数创建),但是我无法使其正常工作。请帮助我得到的错误是“系统找不到指定的文件”如何更改“ openFile”功能以打开创建的文件。
JAVASCRIPT CODE:
function submitOrder(file)
{
var fso = new ActiveXObject ("scripting.filesystemobject")
var newfile = fso.createTextFile (file,true);
var string = "";
var orderlist = document.getElementById("orderlist");
for (i=0; i < orderlist.length; i++)
{
if ( orderlist.options[i].text != "list of ordered items" )
{
string = string + orderlist.options[i].text + '\r\n';
}
}
newfile.WriteLine(string);
newfile.Close();
alert('Your order has been submitted to the text file ' + file);
}
function OpenFile(file)
{
wshell = new ActiveXObject("WScript.Shell");
wshell.run("Z:\Local\eric.mahinay\Assignment 4 Programming" + file ,1,false);
}
以下HTML代码:
<body onload="screen();">
<h1>Gigantuano Pizza Company</h1>
<p>Place your order now!</p>
<select id="pizza" >
<option value="0.00">Select a pizza</option>
<option value="10.00">Hawaiian - Large Stuffed Crust - $10.00</option>
<option value="8.00">Hawaiian - XL Standard Base - $8.00</option>
<option value="13.50">Hawaiian - XL Stuffed Crust - $13.50</option>
<option value="10.00">Beef and Onion - Large Stuffed Crust -
$10.00</option>
<option value="8.00">Beef and Onion - XL Standard Base - $8.00</option>
<option value="13.50">Beef and Onion - XL Stuffed Crust - $13.50</option>
<option value="11.00">Peperoni Lovers - Large Stuffed Crust -
$11.00</option>
<option value="13.50">Chicken Supreme - Large Stuffed Crust -
$13.50</option>
</select>
<input type ="button" onclick="addOrderItem()" value="Add Order Item"><br>
<br>
Ordered Items: click to check order
<select id="orderlist"><option value="0.00">list of ordered items</option>
</select>
<input type ="button" onclick="removeOrderItem();" value="Remove Order
Item">
<br>
Order Total: <input type ="text" id="ordertotal" value=0.0></input><br>
<br>
<br>
Type your order submission file name (one word):<input type ="text"
id="orderfilename" value=""></input>
Click to submit your order:
<input type ="button"
onclick="submitOrder(document.getElementById('orderfilename').value +
'.txt');" value="Submit Order">
<input type="button" value="Open Order Text File" onclick="OpenFile(
document.getElementById('orderfilename').value + '.txt' );"/>
<br>
</body>
</html>