<script>
function sel(_this){
  var obj_right=document.getElementById("content")
  var tmp_str=(obj_right.value==""?"":"\n")+_this.innerHTML
  obj_right.value+=tmp_str
  _this.style.color="#aaa"
//  _this.title="该数据已被点击过"
  _this.onclick=function(){alert("该数据已被点击过")}
}
</script>
<script language="JavaScript">
function $(_o){return document.getElementById(_o)}function SetCookie(content,value)//两个参数,一个是cookie的名子,一个是值
{
    var Days = 1; //此 cookie 将被保存 1 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = content + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(content)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+content+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;}
function delCookie(content)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(content);
    if(cval!=null) document.cookie= content + "="+cval+";expires="+exp.toGMTString();
}</script>
<table>
<TR>
<TD width="161">
<A class="STYLE3" onClick="sel(this)" style="cursor:hand;">点击自动添加内容</A><br>
<A class="STYLE3" onClick="sel(this)" style="cursor:hand;">1111111</A><br>
<A class="STYLE3" onClick="sel(this)" style="cursor:hand;">22222222</A><br>
</TD>
<TD width="161"><textarea name="content" rows="6" cols="54"></textarea>
</TD>
</TR>
</table>
各位帮忙看看是哪里错了!没有效果啊!
主要想实现刷新后被点击过的内容颜色不变或者做个提示该数据被点了几次? 

解决方案 »

  1.   


    <body>
    <script>
    //点击过//
    function getCookie(content){//取cookies函数        
        var arr = document.cookie.match(new RegExp("(^| )"+content+"=([^;]*)(;|$)"));
         if(arr != null) return unescape(arr[2]); return null;}
    function delCookie(){//删除cookie
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval=getCookie(content);
        document.cookie= "selectSTR=null;expires="+exp.toGMTString();
    }
    function SetCookie(){//两个参数,一个是cookie的名子,一个是值
        var obj=document.getElementById("infs").getElementsByTagName("a"),j=obj.length
        var selectSTR=""
        for (var i=0;i<j;i++){
         var tmpSTR=(obj[i].caiying2009?1:0)+"|"
         selectSTR+=tmpSTR
        }
        selectSTR=selectSTR.substr(0,selectSTR.length-1);
        
        var Days = 1; //此 cookie 将被保存 1 天
        var exp = new Date();    //new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = "selectSTR="+ escape (selectSTR) + ";expires=" + exp.toGMTString();
    }function setCSS(_this,t,s){
      _this.title=s
      _this.caiying2009=t
      if (t) _this.style.color="#aaa"//或设置className
      else _this.style.color="#000"//或设置className
    }
    function sel(_this){
      var obj_right=document.getElementById("content")
      var tmp_str=(obj_right.value==""?"":"\n")+_this.innerHTML
      obj_right.value+=tmp_str
      var t=1
      setCSS(_this,t,"该数据已被点击过")
      SetCookie()
      _this.onclick=function(){alert("该数据已被点击过")}
    }
    function init(){
    var selectSTR=null
    if (getCookie("selectSTR"))selectSTR=getCookie("selectSTR").split("|")
        var obj=document.getElementById("infs").getElementsByTagName("a"),j=obj.length
        for (var i=0;i<j;i++)
            if (obj[i].className=="STYLE3"){
                var t=null
                if (selectSTR)t=parseInt(selectSTR[i])
                setCSS(obj[i],t,"点击自动添加内容")
                obj[i].onclick=function(){sel(this)}
            }
    }function reset(){
    delCookie()
    init()
    }onload=init
    </script>
    <table>
    <TR>
    <TD width="161" id=infs>
    <A class="STYLE3" style="cursor:hand;">点击自动添加内容</A><br>
    <A class="STYLE3" style="cursor:hand;">1111111</A><br>
    <A class="STYLE3" style="cursor:hand;">22222222</A><br>
    </TD>
    <TD width="161"><textarea name="content" rows="6" cols="54"></textarea>
    </TD>
    </TR>
    </table>
    <br>
    <input type=button onclick="reset()" value="reset"></body>