写cookie
var LargeExpDate = new Date ();
LargeExpDate.setTime(LargeExpDate.getTime() + 1000*3600*24);
document.cookie = "cname=" + escape (value)+";expires=" +LargeExpDate.toGMTString();至于不重复写,那就简单了,每个文本给一个变量,再连起来,或者按文本框数量自动定义一个对应数组,取值时用join连起来就行了
var LargeExpDate = new Date ();
LargeExpDate.setTime(LargeExpDate.getTime() + 1000*3600*24);
document.cookie = "cname=" + escape (value)+";expires=" +LargeExpDate.toGMTString();至于不重复写,那就简单了,每个文本给一个变量,再连起来,或者按文本框数量自动定义一个对应数组,取值时用join连起来就行了
cookies["strclicked"]["数据库1"]=数据库1的值|点击次数
这样你可以通过遍历strclicked,
而得到三个数据库的值与点击次数,
然后通过";"分离,将点击次数增一,重新赋值
<input type="text" name="b" value="数据库值2" onclick='javascript: RecordClick(this.value);' /><br/>
<input type="text" name="c" value="数据库值3" onclick='javascript: RecordClick(this.value);' /><br/>
<input type="text" name="d" value="数据库值4" onclick='javascript: RecordClick(this.value);' /><br/>
<input type="text" id="txtShowMsgClick" value="" style="width: 638px" /><br/>
<a href='#' onclick='javascript: void attachString();'>GO--> B.ASP</a>
<script language="javascript" type="text/javascript">
<!--
var arrClicked= new Array();
arrClicked.existItem = function (value)
{
for(var i=0;i<arrClicked.length;i++)
{
if(arrClicked[i].value == value)
{
return i;
}
}
return -1;
}
function clickItem(clickvalue,clickcount )
{
this.value = clickvalue;
this.count = clickcount;
this.toString = function(){return this.value;}
}
function RecordClick(value)
{
var index = arrClicked.existItem(value);
if(index < 0)
{
index = arrClicked.length;
arrClicked[index] = new clickItem(value,1);
}
else
{
arrClicked[index].count = arrClicked[index].count+1;
}
document.getElementById("txtShowMsgClick").value = "你選中【"+ arrClicked[index].value +"】共【"+arrClicked[index].count+"】次";
}
function attachString()
{
alert(arrClicked.join('|'));
// window.location.href="B.asp?strCicked="+strClicked;
}
//-->
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>body {
font: 1em Verdana, Arial, sans-serif;
background-color: #FFFFFF;
color: #000000;
margin: 1em 0 0 1em;
}
#nav {
padding: 0;
margin: 0;
list-style: none;
width:500px;
position:absolute;
z-index: 3;
}
ul {
width:60px;}
#nav li {
float: left;
position: relative;
width: 10em;
border: 1px solid #B0C4DE;
background-color: #E7EDF5;
color: #2D486C;
text-align: center;
font-size: 80%;
margin-right: 0;
padding: 0;
}
#nav a:link, #nav a:visited {
display: block;
text-decoration: none;
padding-left: 0;
color: #2D486C;
}
* html #nav a {
width: 100%;
}
#nav ul {
display: block;
position: relative;
padding: 0;
}
#nav ul li {
float: left;
border: 0 none transparent;
border-bottom: 1px solid #E7EDF5;
border-top: .5em solid #FFF;
background-color: #F1F5F9;
font-size: 100%;
margin-bottom: -1px;
margin-top: 1px;
padding: 0;
z-index: 4;
}
#nav li:hover ul{
display: block;
z-index: 4;
}
#nav ul li:hover {
display: block;
border: 0 none transparent;
border-bottom: 1px solid #E7EDF5;
border-top: .5em solid #FFF;
background-color: #c0c0c0;
margin-bottom: -1px;
margin-top: 1px;
padding: 0;
z-index: 3;
}
#content {
top: 3.6em;
left: 0;
width: 100%;
height: 20em;
position: absolute;
/*absolute: bottom; */
background-color: #CC0033;
z-index: 1;
}</style>
</head>
<body id="bodyContent"><script>
collect = []
len = 0
loop = 0
n =2;
elen = 5
function getcollect(array,num){
var a = new Array();
a= array;
if(array.length<num)return;
if(loop>100000)return;
for(i=0;i<elen -num;i++){
if(collect[len]&&len!=0)
collect[len]+=array[i]+",";
else
collect[len]=array[i]+",";
c = collect[len]
alert(i+":"+c)
if(num==2){
for(j=1;j<array.length;j++){
// alert(array[j]);
collect[len]=array+":["+len+"]:"+c+array[j]+";<br>";
len++
}
// getcollect(array.slice(1),num-1);}
}
else if(array.length == elen - num)
for(j=1;j<array.length-n;j++){
// alert(array[j]);
collect[len]=array+"::["+len+"]:"+c+array[j]+";<br>";
len++
}// getcollect(a.slice(1),num-1);
}
}
//getcollect([1,2,3,4,5],2)
//alert(loop);
//document.write (collect);
//12345
//12
</script> 这里显示
<input type=text name=a value="数据库值1" onclick='javascript: RecordClick(this.value);'><br>
<input type=text name=b value="数据库值2" onclick='javascript: RecordClick(this.value);'><br>
<input type=text name=c value="数据库值3" onclick='javascript: RecordClick(this.value);'><br>
<input type=text name=d value="数据库值4" onclick='javascript: RecordClick(this.value);'><br><br>
<a href='#' onclick='javascript: void attachString();'>GO--> B.ASP</a><script language=javascript>
var strClicked="";
function RecordClick(s){
//加此句即可
// alert(strClicked.indexOf(s)<0);
if(strClicked.indexOf(s)<0){
strClicked=strClicked+"|"+s;
document.getElementById("counts").innerHTML = strClicked.match(/(.*?)(\|)(.*?)/g).length;
}
// alert(strClicked);
}function attachString(){
strClicked=strClicked.substr(1,strClicked.length);
window.location.href="B.asp?strCicked="+strClicked
}</script>
你选中了 <span id=counts>X</span> 次
</body>
</html>