ファイルdemo.html
<!doctype html public - // w3c // dtd html 4.0 transitional // en>
<html>
<head>
<メタ名=ジェネレーターコンテンツ= Microsoft Visual Studio 7.0>
<title> </title>
</head>
<スクリプト言語= javascript>
function onload()
{
var str = window.dialogarguments;
if(str!=未定義)
{
var arr = str.split( - );
if(arr.length == 2)
{
frmmain.txtname.value = arr [0];
frmmain.txtamount.value = arr [1];
}
}
}
function onsubmit()
{
if(frmmain.txtname.value == || frmmain.txtamount.value ==)
{
アラート(都要填);
falseを返します。
}
else if(!isdigit(frmmain.txtamount.value)))
{
アラート(金額必须是数字);
frmmain.txtamount.focus();
frmmain.txtamount.select();
falseを返します。
}
それ以外
{
var odemo = new demo(frmmain.txtname.value、frmmain.txtamount.value);
window.returnvalue = odemo;
window.close();
}
}
関数デモ(名前、金額)
{
this.name = name;
this.Amount =額;
this.toString = function()
{
this.name + - + this.amountを返します。
};
this.fromString = function(str)
{
var arr = str.split( - );
if(str ==)
{
this.name =;
this.amount = 0;
}
else if(arr.length == 2)
{
this.name = arr [0];
this.amount = arr [1];
}
それ以外
{
アラート(格式错误);
falseを返します。
}
};
}
関数isdigit(str)
{
for(var i = 0; i <str.length; i ++)
{
var ch = str.charat(i);
if(ch <'0' || ch> '9')
{
falseを返します。
}
}
trueを返します。
}
</script>
<body onload = onload()>
<form name = frmmain>
<テーブル幅= 200 align = center>
<tr>
<td width = 50>名前:</td>
<td> <入力タイプ=テキスト名= txtname size = 10> </td>
</tr>
<tr>
<td width = 50>量:</td>
<td> <入力タイプ=テキスト名= txtamount size = 10> </td>
</tr>
<tr>
<td align = center> <input type = button onclick = onsubmit()value =确定> </td>
</tr>
</table>
</form>
</body>
</html>