原創(chuàng)|其它|編輯:郝浩|2009-09-01 09:59:09.000|閱讀 367 次
概述:本文介紹了Javascript類的繼承方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
JavaScript中類的學(xué)習(xí),從基本類繼承過來方法也可以這樣實現(xiàn):
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中沒反應(yīng)。。
function newClass(){
this.firstName="frank";
this.toUc=String.toUpperCase;
this.toString=function(){
return this.toUc(this.firstName);
}
}
var nc=new newClass();
alert(nc);//在IE中沒反應(yīng)。。
一個簡單的客戶端驗證
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">
<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>
一般這樣寫
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" >
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:IT專家網(wǎng)