javascript动态创建控件的3种方法
以创建按钮为例
<html>
<head>
<script>
function add1()
{
var obtn=document.createElement("input");
obtn.setAttribute("type","button");
obtn.setAttribute("value","test1");
document.body.appendChild(obtn);//注意如果有form表单不要忘记加入表单
}
function add2()
{
var obtn=document.createElement("input");
obtn.type="button";
obtn.value="test2";
document.body.appendChild(obtn);
}
function add3()
{
var obtn="<input type='button' value='test3'/>";
document.body.innerHTML=obtn;//这个方法会删除body中的其它控件 可以预先加到固定的容器中
}
</script>
</head>
<body>
<input type="button" value="add1" onclick="add1()"/>
<input type="button" value="add2" onclick="add2()"/>
<input type="button" value="add3" onclick="add3()"/>
</body>
</html>
相关文档:
1,对象的构成
对象有特性构成(attribute),可以是原始值,也可以是引用值。如果特性存放的是函数,它将被看做对象的方法(method),否则该特性被看做属性(property)。
2,定义类或对象
(1)工厂方式
Code
function createCar(sColor,iDoors) {
&nb ......
1, js中的类数组对象
(1) arguments对象:
function(){
//arguments对象是Arguments对象实例,是一个类数组对象,并拥有下列方法
alert(arguments instanceof Array);//false
arguments.callee(); //对自身的调用, 用于递归
var c = arguments.caller; //对调用自身函数的父函数, 如果 ......
在第一章中,我们使用构造函数和原型的方式在JavaScript的世界中实现了类和继承, 但是存在很多问题。这一章我们将会逐一分析这些问题,并给出解决方案。
注:本章中的jClass的实现参考了Simple JavaScript Inheritance
的做法。
首先让我们来回顾一下第一章中介绍的例子:
function Person(name) {
this.name = nam ......
Javascript刷新页面的几种方法:
程序代码
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refres ......