首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

取舍进行产品比较的脚本

2012-11-06 
选择进行产品比较的脚本script LANGUAGEJavaScript!--document.write(div idfloat styleposi

选择进行产品比较的脚本
<script LANGUAGE="JavaScript">
<!--
document.write('<div id="float" style="position:absolute;left:5px;top:200;filter:alpha(opacity=50);z-index:99;width:140;" align=center dir="rtl"></div>');
if(typeof(doc_ad_array)==""){
var doc_ad_array = new Array();}
function readCookie(name){
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0){
offset = document.cookie.indexOf(search);
if (offset != -1){
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end))}}
return cookieValue;}
function writeCookie(name, value, hours){
var expire = "";
if(hours != null){
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();}
document.cookie = name + "=" + escape(value) + expire;}
lastScrollY = 0;
function heartBeat(){
diffY      = document.body.scrollTop;
percent =.1*(diffY-lastScrollY);
if(percent>0)
percent = Math.ceil(percent);
else
percent = Math.floor(percent);
document.all.float.style.pixelTop+= percent;
lastScrollY = lastScrollY+percent;}
window.setInterval("heartBeat()",1);
function hide(){
obj=document.getElementById("float");
obj.style.display='none';}
function redraw(){
heartBeat();
tmp=readCookie("pro_str");
item_arr=tmp.split("###");
floatstr = "<table height=100% width=100% border=0 bgcolor='#ffffff'>"+
"<form method='post'  name='compare' target='_blank'>"+
"<tr><td align=center height=26><font color=red><strong>〖产品比较篮〗</strong></font></td></tr>"+
"<tr><td><center>"+
"";
for(key in item_arr){
if (key){
//元素形如:2132|我的产品测试
tmp_info_arr=item_arr[key].split("|");
pid  = tmp_info_arr[0];
names= tmp_info_arr[1];
if (pid && names){
ft = "<font color=red size=1>|</font><br><input type=button name=name value='"+names+"' onclick="del('"+pid+"','"+names+"')" style='border:1px solid;border-color:red ;background-color:white;height:24;width:150;cursor:hand;color:'black';'><input type='hidden' name='pro_id[]' value='"+pid+"'><br>";
floatstr = floatstr+ft;}}}
floatstr = floatstr + "<input type='hidden' name='subcatid' value='"+readCookie("subcat")+"'><br>&nbsp;&nbsp;&nbsp;<a href='#' href_cetemp='#' href_cetemp='#' onclick='empty()'><font color=blue>清空</font></a> &nbsp;&nbsp;<a href=# onclick='hide_layer(float)'><font color=blue>隐藏</font></a></center></td></tr>"+
"<tr><td align=center><input type='button' value='产品比较' name='submits'  onclick="comparecheck('bijiao.asp');" style='cursor:hand;width:100px'>"+
"</td></tr></form></table>";
float.style.left='620px';
float.innerHTML = floatstr;}
function empty(){
writeCookie("subcat","");
writeCookie("pro_str","");
redraw();}
function comparecheck(url){
obj=document.compare;
if(url){
obj.action=url;}
mark=0;
for(k=0;k<obj.elements.length;k++){
if (obj.elements[k].name=="pro_id[]"    &&  obj.elements[k].value!=""){
if (obj.elements[k].value.indexOf("undefined")!=(-1)){
obj.elements[k].value=obj.elements[k].value.replace("undefined","");}
mark++;}}
if(mark<2){
alert ('系统提示:请至少选择两款产品进行比较!!!\r\n选择方法:点击对应产品名称前的选择框即可添加该产品到产品对比篮。\r\n删除方法:点击比较篮中的产品名称即可完成去除比较篮中相应的产品。 '); }
else{
obj.submit();}}
//pro_str:产品字符串
//subcat :子类字符串
function change_select(pid,name){
//读出产品串后用函数返回一个数组
tmp=readCookie("pro_str");
//alert(tmp+"=="+pid+"==="+tmp.indexOf(pid));
if (tmp.indexOf(pid)!=-1){
del(pid,name);}
else{
add(pid,name);}}
function add(pid,names){
//读出产品串后用函数返回一个数组
tmp=readCookie("pro_str");
//检查数组的个数(即选择产品的个数)
tmp_arr=stringToArray(tmp,"###");
if (tmp_arr.length<5){
//看是否有相同的产品已被选择
//alert(tmp+"=="+pid+"==="+tmp.indexOf(pid));
if (tmp.indexOf(pid)!=-1){
alert("("+names+")已经被选择了!!!");}
else{
writeCookie("pro_str",tmp+pid+"|"+names+"###");}}
else{
alert("对不起,您只能一次最多选择4款产品进行比较!!!");}
redraw();
writeCookie("hid_float", 0, 100);}
//用指定的字符串div切开str字符串后返回一个数组
function stringToArray(str,div){
objArr=str.split(div);
return objArr;}
function del(pid,name){
tmp=readCookie("pro_str");
writeCookie("pro_str",tmp.replace(pid+"|"+name+"###"));
tmp=readCookie("pro_str");
//如果没有产品了,自动清空subcat
if (tmp=="" || tmp==null){
writeCookie("subcat","");}
redraw();}
redraw();
function hide_layer(id){
writeCookie("hid_float", 1, 100);
id.style.left='-1000px';}
if (readCookie("hid_float")==1){
hide_layer(float);}
else{
tmp=readCookie("pro_str");
if (tmp=="")
hide_layer(float);}
//-->
</script>
<INPUT  onclick="javascript:change_select(208,'3M固体水晶蜡')"type=checkbox>
<INPUT  onclick="javascript:change_select(150,'高尔夫球筒')" type=checkbox> 

热点排行