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>
相关文档:
<script language="JavaScript" type="text/JavaScript">
<!--
function displayScreenSize()
{
var bodyWidth ......
Javascript 获取radiobuttonlist(单选框)的值
function check() {
var RadioButtonList1 = document.getElementById('<%=RadioButtonList1.ClientID%>');
......
1, js中的类数组对象
(1) arguments对象:
function(){
//arguments对象是Arguments对象实例,是一个类数组对象,并拥有下列方法
alert(arguments instanceof Array);//false
arguments.callee(); //对自身的调用, 用于递归
var c = arguments.caller; //对调用自身函数的父函数, 如果 ......
这一章我们将会重点介绍JavaScript中几个重要的属性(this、constructor、prototype), 这些属性对于我们理解如何实现JavaScript中的类和继承起着至关重要的作用。
this
this表示当前对象,如果在全局作用范围内使用this,则指代当前页面对象window; 如果在函数中使用this,则this指代什么是根据运行时此函数在什 ......
Javascript刷新页面的几种方法:
程序代码
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refres ......