<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>11</title>
<script>
function ss(){
this.obj=document.getElementById("sss")
}
var sss=new ss();
</script>
</head>
<body>
<div>
<input type="text" id="sss" />
<input type="button" style="width:100px" value="保存" onclick="sss.checkss()" />
</div>
</body>
</html>
<script>
ss.prototype.checkss=function(){
alert(sss.obj.value);
}
</script>
命名不规范了点请大家谅解我想啊 为啥sss.obj.value 不存在呢?
this.obj="ss"这样sss.obj肯定是有值的 嘿嘿 问问大家
function ss(){
this.obj=document.getElementById("sss")
}
var sss=new ss();
</script>
写到最后面去! var sss=new ss(); 执行这句时,还没加载下面的html 。 document.getElementById("sss") 为 null!或者: ss.prototype.checkss=function(){
this.obj = this.obj||document.getElementById("sss");
alert(sss.obj.value);
}