这个可以实现点击自动添加内容,但是发现刷新后就恢复了。有没有办法实现刷新后被点击过的内容颜色不变或者做个提示该数据被点了几次?
<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>
<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>
<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>
<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>
还有LZ你的JS里面好象有点错误
现在我也在试这个东西
不过我觉得你想保存前来可以用cookie或seccoin
不知道你是用那种语言做的开发
不过我可以正常运行啊!
<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">
<!--hide from nonJavaScript browsers
function getCookieVal (offset) {
//函数getCookieVal()的说明
}
function GetCookie(name) {
//函数GetCookie()的说明
}
function SetCookie (name,value) {
//函数SetCookie()的说明
}
function DeleteCookie(name) {
//函数DeleteCookie()的说明
}
var cookie-data=new Date
(document.lastModified);
var expdate=new Date();
expdate.setTime(expdate.getTime()+
(5*24*60*60*1000));
document.write("This page last updated
on:"+document.lastModified);
document.write("<br>");
if(!(cookie-data==GetCookie("cookie-
date"))){
SetCookie("cookie-date",cookie-
date,expdate);
document.write("<font color='Red'>
This page has changed since your last
visit!</font><br>");
}
// end hide->
</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>这样改了下 没有效果 是不是哪里没弄对啊?
<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>