中类的学习,从基本类继承过来方法
也可以这样实现:
JavaScript代码
function newClass(){
this.firstName="frank";
this.toUc=String.toUpperCase;
this.toString=function(){
return this.toUc(this.firstName);
}
}
var nc=new newClass();
alert(nc);//在IE中没反应。。
function newClass(){
this.firstName="frank";
this.toUc=String.toUpperCase;
this.toString=function(){
return this.toUc(this.firstName);
}
}
var nc=new newClass();
alert(nc);//在IE中没反应。。
一个简单的客户端验证
JavaScript代码
<html>
<head>
<title>javascript</title>
<script type="text/javascript">
function doSubmit(inForm){
if(inForm.firstName.value==""){
alert("firstName is null");
return false;
}
if(inForm.lastName.value ==""){
alert("lastName is null");
}
inForm.submit();
return true;
}
</script>
</head>
<body>
<form action="#" name="test" method="post">
First name: <input type="text" name="firstName">
<br>
Last name:<input type="text" name="lastName">
<br>
<input type="button" value="submit" onclick="doSubmit(this.form);">
</form>
</body>
</html>
</form>
<html>
<head>
<title>javascript</title>
<script type="text/javascript">
function doSubmit(inForm){
if(inForm.firstName.value==""){
alert("firstName is null");
return false;
}
if(inForm.lastName.value ==""){
alert("lastName is null");
}
inForm.submit();
return true;
}
</script>
</head>
<body>
<form action="#" name="test" method="post">
First name: <input type="text" name="firstName">
<br>
Last name:<input type="text" name="lastName">
<br>
<input type="button" value="submit" onclick="doSubmit(this.form);">
</form>
</body>
</html>
</form>
一般这样写
JavaScript代码
<form action="#" name="test" method="post" onSubmit="return doSubmit(this);">
First name: <input type="text" name="firstName">
<br>
Last name:<input type="text" name="lastName">
<br>
<input type="button" value="submit" >