a.onclick=addEmotion(num);
这里需要闭包a.onclick=function(){addEmotion(num);}<!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" />
<script  src="jquery-1.3.2.min.js"></script>
<script  type="text/javascript">
function CreateImg(num)
{
  var a=document.createElement("a");
  a.setAttribute("href","#");
  a.onclick=function(){addEmotion(num)};
  a.innerHTML="ccc";
  document.getElementById("a").appendChild(a);
  return a;
}function addEmotion(num)
{
alert(num)
}
window.onload=function(){CreateImg(3)}
</script>
<title>无标题文档</title>
</head><body><div id="a"></div></body>
</html>

解决方案 »

  1.   

    汗..没注意 测试的时候把jquery也加上了..
      

  2.   

    function CreateImg(num)
    {
      var a=document.createElement("a");
      a.setAttribute("href","#");
      (
        function(o,m){
         o.onclick=function(){addEmotion(m);}
        }
      )(a,num);
      a.innerHTML="ccc";
      document.getElementById("a").appendChild(a);
      return a;
    }
      

  3.   

    addEmotion(m);是另外一个函数,怎么还要加进去啊?function addEmotion(addr)
    {
      getEditor().focus();
      getEditor().value+="[face"+addr+"]";
    }