webservice结合dhtml的简单例子(三,漏贴一个文件,呵呵)
2024-08-26 00:15:33
供稿:网友
file 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>
<script language="javascript">
function onload()
{
var str = window.dialogarguments ;
if(str != undefined)
{
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 == "")
{
alert("都要填") ;
return false ;
}
else if(!isdigit(frmmain.txtamount.value))
{
alert("amount必须是数字") ;
frmmain.txtamount.focus() ;
frmmain.txtamount.select() ;
return false ;
}
else
{
var odemo = new demo(frmmain.txtname.value , frmmain.txtamount.value) ;
window.returnvalue = odemo ;
window.close() ;
}
}
function demo(name , amount)
{
this.name = name ;
this.amount = amount ;
this.tostring = function()
{
return 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] ;
}
else
{
alert("格式错误") ;
return false ;
}
};
}
function isdigit(str)
{
for(var i = 0 ; i < str.length ; i ++)
{
var ch = str.charat(i) ;
if(ch < '0' || ch > '9')
{
return false ;
}
}
return true ;
}
</script>
<body onload="onload()">
<form name="frmmain">
<table width="200" align="center">
<tr>
<td width="50">name:</td>
<td><input type="text" name="txtname" size="10"></td>
</tr>
<tr>
<td width="50">amount:</td>
<td><input type="text" name="txtamount" size="10"></td>
</tr>
<tr>
<td align="center"><input type="button" onclick="onsubmit()" value="确定"></td>
</tr>
</table>
</form>
</body>
</html>