Javascript继承机制(call、apply、prototype)
Javascript的继承可以通过call、apply、prototype实现。
1、call:在子类中,用父类.call(this,arg0,arg1...)可以继承父类。注意call的位置,尽量在子类的第一行(js按顺序执行,放在后面可能对子类的其他属性、方法有影响。比如子类和父类有相同名字的方法,后面的覆盖前面的)。
<html>
<head>
<title>call\apply\prototype test</title>
</head>
<script type="text/javascript">
//person类
function person(name, age) {
this.name = name;
this.age = age;
this.say = function() {
document.write("I am a person");
}
this.display = function() {
document.write(this.name + "-" + this.age);
}
}
//student类,继承自person
function student(name, age, no) {
person.call(this, name, age);//person中的this等于参数中的this,即student中的name和age
this.no = no;
this.display = function() {//覆盖了父类的方法
document.write(this.name + "-" + this.age + "-" + this.no);
}
}
//创建person类
var p = new person("captain", 21);
p.display();//captain-21
p.say();//I am a person
//创建student类
var s = new student("captain", 21, "06281097")
s.display();//captain-21-06281097
s.say();//I am a person 继承了父类的方法
<script>
<body>
</body>
</html>
2、apply:在子类中,用父类.apply(this,args)可以继承父类(args为参数数组)。
<html>
<head>
<title>call\apply\prototype test</title>
</head>
<script type="text/javascript">
//person类
function person(name, age) {
this.name = name;
this.age = age;
this.say = function() {
document.write("I am a person");
}
this.display = function() {
document.write(this.name + "-" + this.age);
}
}
//student类,继承自person
function student(name, age, no) {
person.apply(this, new Array(name, age));//与call不同的是,apply传递的是数组
this.no = no;
this.display = function() {//覆盖了父类的方法
document.write(this.name + "-" + this.age + "-" + this.no);
}
}
//创建pe
相关文档:
scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetL ......
1.如何获取表单<select>域的选择部分的文本?
<form name="a">
<select name="a" size="1" onchange="_sel(this)">
<option value="a">1</option>
<option value="b">2</option>
<option value="c">3</option>
</select>
</form&g ......
ADF 11g不再支持Onclick等JavaScript,而是采用<af:clientListener>来实现诸如删除某条记录的提示框。
实现方式如下:
function confirmDelete() {
if (confirm('Are you sure you want to delete this record?'))
return true;
else
return false;
}
<af:commandLink actionListener="# ......
前台页面为 子页面为一个按钮:
<form id="form1" runat="server">
<div>
<asp:Button runat="server" ID="Bt_Add" Text="添加" Width="80px" Height="20px" OnClick="Bt_Add_Click" />
</div>
  ......
自定义控件中的页面代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wcontrol.ascx.cs" Inherits="wcontrol" %>
<script type ="text/javascript">
function PopupCalendar(InstanceName)
{
///Global Tag
this.instanceName=InstanceName;
///Properties
this.separator="-"
t ......