ملف demo.html
<! doctype html public -// w3c // dtd html 4.0 transitional // en>
<html>
<head>
<meta name = Generator Content = Microsoft Visual Studio 7.0>
<title> </title>
</head>
<لغة البرنامج النصي = javaScript>
وظيفة onload ()
{
var str = window.dialogarguments ؛
إذا (str! = غير محدد)
{
var arr = str.split (-) ؛
if (arr.length == 2)
{
frmmain.txtName.value = arr [0] ؛
frmmain.txtamount.value = arr [1] ؛
}
}
}
وظيفة onSubmit ()
{
if (frmmain.txtname.value == || frmmain.txtamount.value ==)
{
تنبيه (都要填) ؛
العودة كاذبة
}
آخر إذا (! isDigit (frmmain.txtamount.value))
{
تنبيه (المبلغ 必须是数字) ؛
frmmain.txtamount.focus () ؛
frmmain.txtamount.select () ؛
العودة كاذبة
}
آخر
{
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 (-) ؛
إذا (str ==)
{
this.name = ؛
this.amount = 0 ؛
}
آخر إذا (arr.length == 2)
{
this.name = arr [0] ؛
this.amount = arr [1] ؛
}
آخر
{
تنبيه (格式错误) ؛
العودة كاذبة
}
} ؛
}
وظيفة isdigit (str)
{
لـ (var i = 0 ؛ i <str.length ؛ i ++)
{
var ch = str.charat (i) ؛
if (ch <'0' || ch> '9')
{
العودة كاذبة
}
}
العودة صحيح.
}
</script>
<body onload = onload ()>
<اسم النموذج = frmmain>
<عرض الجدول = 200 محاذاة = المركز>
<tr>
<td width = 50> الاسم: </td>
<td> <input type = text name = txtname size = 10> </td>
</r>
<tr>
<TD عرض = 50> المبلغ: </td>
<td> <input type = text name = txtamount size = 10> </td>
</r>
<tr>
<td align = center> <type type = button onClick = OnSubmit () value = 确定> </td>
</r>
</table>
</form>
</body>
</html>