程序改写:函数传递参数改为数组形式
本程序直接复制到记事本中可运行,要求把函数传递参数改为数组形式;例如:onClick="D.UpdateInfo()"改为:onClick="UpdateInfo(D)"这种想法可行吗?怎么改,期侍你的指教!谢谢
<html><head><title>数组对象</title>
<script language="JavaScript">
function updateInfo()
{//对象book的方法成员,修改对象属性值
document.BookForm.currbook.value=this.Currbook;
document.BookForm.BookTitle.value=this.Title;
document.BookForm.BookPublisher.value=this.Publisher;
document.BookForm.BookAmount.value=this.Amount;
}
function Book(currbook,title,publisher,amount)
{//对象book的构造函数
this.Currbook=currbook;
this.Title=title;
this.Publisher=publisher;
this.Amount=amount;
this.UpdateInfo=updateInfo;
}
</script></head>
<body><script language="JavaScript">
var Books=new Array(); //创建数组,数组元素是book对象
//为数组各元素赋值
A=new Book("A","语文","少年儿童出版社",10000);
B=new Book("B","数学","高等教育出版社",5000);
C=new Book("C","普通物理","高等教育出版社",3000);
D=new Book("D","计算机基础","清华大学出版社",2000);
</script>
<h2 align=center>共有四本书,可选择查看其信息</h2>
<form name="BookForm">
选择当前所显示的书:
<input type=button value=A书 onClick="A.UpdateInfo()">
<input type=button value=B书 onClick="B.UpdateInfo()">
<input type=button value=C书 onClick="C.UpdateInfo()">
<input type=button value=D书 onClick="D.UpdateInfo()"><br><br>
当前书:<input type="text" name="currbook" value="A书"><br><br>
书名:<input type="text" name="BookTitle" value="语文"><br><br>
出版社:<input type="text" name="BookPublisher" value="少年儿童出版社"><br><br>
印数:<input type="text" name="BookAmount" value="10000">
</form></body></html>