<!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>无标题文档</title>
</head>
<style type="text/css">
#main { width:500px; height:500px;}
#maa { width:200px; height:150px; float:left; border:#000 solid 1px; position:relative;}
#mbb { width:200px; height:150px; float:left; border:#000 solid 1px; position:absolute; margin-left:5px;}
.class { border:#666 solid 1px; background-color:#D9ECFF;}
.class1 { color:#999; font-size:12px;}
.class1:hover { color:#090; font-size:12px; font-weight:bold;}
</style>
<script type="text/javascript">
var o= document.getElementById(a);
function yingchang()
{
if(document.getElementById("mbb").style.display=="none")
{
document.getElementById("mbb").style.display="block";
}
else
{
document.getElementById("mbb").style.display="none";
}
}
function fun(a,x)
{
var o= document.getElementById(a);
o.value+=x;
}
</script><body>
<div id="main">
<div id="maa">
<p>
<input name="textfield" type="text" class="class" id="tex" onfocus="yingchang()" />
</p>
<p>
<a href="#" class="class1" onclick="yingchang()">打开软键盘 </a></p>
</div>
<div id="mbb" style="display:none;">
<a href="#" onclick="fun('tex',1)">1</a>
<a href="#" onclick="yingchang()">关闭</a>
</div>
</div>
</body>
</html>var o= document.getElementById(a);这句话 定义在fun(a,x) 方法里面就可以。 但是定义在方法外面却不行.
定义在方法外面的变量,方法里面不可以引用的么?
解决方案 »
- 用js实现,当点击菜单中的某一项时,有背景色出现。
- 【比如在网页源文件下使用document.getElementById("xxx").style.display='none';代码,在JS外部文件如何写?】
- 按钮自动点击问题
- 有关JavaScript作用域与闭包的问题,求帮忙解答
- 在线求救-----急!!!
- 关于JS广告的问题-急切~
- 30分求gridview 中checkbox 取值问题
- <input type=text name=aa id=11>用javascript根据id,能不能得到name
- 怎么获得字节数?
- jQery创建元素时效率问题
- 关于对特定字符串的解析的问题,请大家不吝赐教!!
- 关于window.onload
定义在外面那a是什么?
而且document.getElementById需要在html完全加载完毕之后才可以用
var o; //定义变量function fun(a,x)
{
o= document.getElementById(a); //对已经定义过的变量进行存取
o.value+=x;
}