<!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">
* { font-size:12px; color:#333;}
#main { width:600px; height:600px; position:relative; background-color:#FFE1E1;}
#mm1 { width:250px; height:150px; background-color:#DFEFFF; border:#666 solid 1px; float:left;}
.class1 { width:150px; height:20px; border:#CCC solid 1px; color:#333; font-size:12px;}
#mm1 ul { margin-top:20px;}
#mm1 li { margin-top:5px; list-style-type:none;} 
#mm2 { width:250px; height:150px; background-color:#DFEFFF; border:#666 solid 1px; float:left; position:absolute; margin-left:5px;}
.class a { width:18px; height:18px; background-color:#FFD2D2; border:#999 solid 1px; display:block; text-align:center; margin:0 auto; padding-top:2px; text-decoration:none; margin-top:1px;}
</style>
<script type="text/javascript">
function fan()
{
if(document.getElementById("mm2").style.display=="none")
{
document.getElementById("mm2").style.display="block";
}
else
{
document.getElementById("mm2").style.display="none";
     }
function fun(x)
{
document.getElementById("mm3").value+=x;
}
}
</script>
<body>
<div id="main">
  <div id="mm1">
        <ul>欢迎登陆游戏
        <li> <input type="text" name="textfield" id="tex"  class="class1"/></li>
        <li> <input name="" type="text" class="class1" onfocus="fan()" id="mm3" /></li>
        <li><input name="" type="button" value="登陆" /><input name="" type="button" value="注册" /></li>
        </ul>
  </div>
  <div id="mm2" style="display:none;">
<a href="#" onclick="fun(1)">1</a>
<a href="#" onclick="fun(2)">1</a>
<a href="#" onclick="fun(3)">2</a>
<a href="#" onclick="fun(4)">3</a>
<a href="#" onclick="fun(5)">4</a>
<a href="#" onclick="fun(6)">5</a>
  </div>
</div>
</body>
</html>我想在第2个文本框里面 鼠标获得焦点的时候出现层 mm2 这个已经实现了。
在mm2层里面有 超连接。 点击超级链接把值赋给 文本框mm3  怎么点击提示 缺少对象呢!function fun(x)
{
document.getElementById("mm3").value+=x;
}这句哪里错了? 麻烦高手看看! 谢谢

解决方案 »

  1.   

    <input name="" type="text" class="class1" onfocus="fan()" id="mm3" />
    onfocus时fan()参数x为null,所以报错document.getElementById("mm3").value为null时,也无法+=
      

  2.   

    楼上说得对  你JS里面是有参函数
    你这里<input name="" type="text" class="class1" onfocus="fan()" id="mm3" /> 
    调用 函数 onfocus="fan()"时  参数却是NULL
      

  3.   

    fan() 本来就是个无参数函数   fun(x) 才是有参函数。    现在问题是调用fun这个有参函数 无法给文本框 mm3 赋值。  
      

  4.   


    function fun(x)
    {
        document.getElementById("mm3").value+=x;
        }
    这个函数是写在JSP里还是javascript里?
    如果是javascript的话,没有任何问题呀,复制你的代码运行后,点超连接输入数据没任何错误。
      

  5.   

    目前还没有见过这种方法,可以用innerHTML给层赋予显示的内容
      

  6.   

    "   document.getElementById("RemimdDiv").value"
    可以直接.value赋值啊~~为什么我这样写不行呢~~