Javascript 类的继承实现代码
作者:bea
JavaScript中类的学习,从基本类继承过来方法 也可以这样实现: Java代码 代码如下: 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中类的学习,从基本类继承过来方法
也可以这样实现:
Java代码
代码如下:
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中没反应。。
一个简单的客户端验证
Java代码
<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">
Last name:<input type="text" name="lastName">
<input type="button" value="submit" onclick="doSubmit(this.form);">
</form>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
<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">
Last name:<input type="text" name="lastName">
<input type="button" value="submit" onclick="doSubmit(this.form);">
</form>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
一般这样写
Java代码
代码如下:
<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" >
有用 | 无用
也可以这样实现:
Java代码
代码如下:
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中没反应。。
一个简单的客户端验证
Java代码
<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">
Last name:<input type="text" name="lastName">
<input type="button" value="submit" onclick="doSubmit(this.form);">
</form>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
<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">
Last name:<input type="text" name="lastName">
<input type="button" value="submit" onclick="doSubmit(this.form);">
</form>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
一般这样写
Java代码
代码如下:
<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" >
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JavaScript 异步调用框架 (Part 3 - 代码实现)
- JavaScript 异步调用框架 (Part 2 - 用例设计)
- JavaScript 异步调用框架 (Part 1 - 问题 & 场景)
- jQuery 相关控件的事件操作分解
- 利用javascript实现一些常用软件的下载导航
- [原创]javascript 定时广告显示(两个时间段)
- jQuery 隔行换色 支持键盘上下键,按Enter选定值
- 一句话JavaScript表单验证代码
- JavaScript 关键字屏蔽实现函数
- Javascript 验证上传图片大小[客户端]
- Javascript 汉字字节判断
- JS 输入字数判断实现代码
- JS 面向对象的5钟写法
- JS 事件冒泡 示例代码
- Document 对象的常用方法
- javascript getElementsByName()的用法说明
- extjs 列表框(multiselect)的动态添加列表项的方法
- JavaScript 学习小结(适合新手参考)
- JavaScript 创建对象和构造类实现代码