<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return "";
}

function setCookie(name, value) {
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var expDay = (argc > 2) ? argv[2] : -1;
    try
    {
        expDay = parseInt(expDay);
    }
    catch(e)
    {
        expDay = -1;
    }
    if(expDay < 0) {
        setCookieVal(name, value);
    } else {
        var expDate = new Date();
        // The expDate is the date when the cookie should expire, we will keep it for a month
        expDate.setTime(expDate.getTime() + (expDay * 24 * 60 * 60 * 1000));
        setCookieVal(name, value, expDate);
    }
}

function deleteCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    // This cookie is history
    var cval = getCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function setCookieVal(name, value) {
    var argv = setCookieVal.arguments;
    var argc = setCookieVal.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
                      ((expires == null || expires < 0) ? "" : ("; expires=" + expires.toGMTString())) +
                      ((path == null) ? "" : ("; path=" + path)) +
                      ((domain == null) ? "" : ("; domain=" + domain)) +
                      ((secure == true) ? "; secure" : "");
}

</script>
<script language="JavaScript">
var status = 0;
var models = new Array();
function updateCompareModel() {
for(var i=0; i<5; i++) {
var model = new Object();
model.bid = getCookie("bid"+i);
model.mid = getCookie("mid"+i);
model.mname = getCookie("mname"+i);
if(model.mid != "") {
models.push(model);
}
}
}
function updateCompareCookie() {
for(var i=0; i<5; i++) {
deleteCookie("bid"+i);
deleteCookie("mid"+i);
deleteCookie("mname"+i);
}
for(var i=0; i<models.length; i++) {
var model = models[i];
if(model.mid != "") {
setCookie("bid"+i, model.bid);
setCookie("mid"+i, model.mid);
setCookie("mname"+i, model.mname);
}
}
}
function updateCompareForm() {
for(var i=0; i<models.length; i++) {
var model = models[i];
if(model.mid != "") {
var modelTr = document.getElementById("compare_model_" + model.mid + "_row");
if(modelTr == null) {
addCompareToForm(model.bid, model.mid, model.mname);
}
}
}
}
function addCompareModel(bid, mid, mname) {
show_db(1);
var modelTr = document.getElementById("compare_model_" + mid + "_row");
if(modelTr == null) {
if(models.length <5) {
setCookie("bid"+models.length, bid);
setCookie("mid"+models.length, mid);
setCookie("mname"+models.length, mname);
var model = new Object();
model.bid = bid;
model.mid = mid;
model.mname = mname;
models.push(model);
updateCompareForm();
} else {
alert("最多只能选择5个车型进行比较");
}
} else {
alert("该车型已经存在于车型对比栏中");
}
}
function removeCompareModel(mid) {
var index = -1;
for(var i=0; i<models.length; i++) {
var model = models[i];
if(model.mid == mid) {
alert("aa");
index = i;
break;
}
}
if(index >= 0) {
for(var i= index; i< models.length; i++) {
models[i] = models[i+1];
}
models.pop();
}
updateCompareCookie();
var modelTr = document.getElementById("compare_model_" + mid + "_row");
modelTr.id = "";
modelTr.style.display = "none";
}
function addCompareToForm(bid, mid, mname) {
var compare_button_row = document.getElementById("compare_button_row");
var compare_model_tr = document.createElement("tr");
compare_model_tr.id = "compare_model_" + mid + "_row";
compare_model_tr.name = "compare_model_row";
var compare_model_td = document.createElement("td");
compare_model_td.className = "series_sy_dbc2";
var compare_model_div = document.createElement("div");
compare_model_div.innerHTML =
'<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">' +
'<tr>' +
'<td class="series_sy_dbc21">' +
'<a href="http://price.pcauto.com.cn/m' + mid + '/" target="_blank">' + mname + '</a>' +
'</td>' +
'<td class="series_sy_dbc22">' +
'<a href="javascript:removeCompareModel(' + mid + ');"><img src="series_sy_21.jpg" width="12" height="12" border="0"></a>' +
'</td>' +
'</tr>' +
'</table>';
compare_model_td.appendChild(compare_model_div);
compare_model_tr.appendChild(compare_model_td);
compare_button_row.parentNode.insertBefore(compare_model_tr, compare_button_row);
}
function show_db(sel) {
var db = document.getElementById("series_sy_db");
if (sel == 1) {
db.style.display = "block";
status = 1;
}
else {
db.style.display = "none";
status = 0;
}
}
function showOrCloseCompareForm() {
if(status==0) {
show_db(1);
status=1;
} else {
show_db(0);
status=0;    
}
}
function genUrl() {
var action = document.getElementById("compare_models_form").action;
for(var i=0; i<models.length; i++) {
if(i == 0) {
action += "?bid_" + (i+1) + "=" + models[i].bid;
} else {
action += "&bid_" + (i+1) + "=" + models[i].bid;
}
action += "&mid_" + (i+1) + "=" + models[i].mid;
}
//        document.getElementById("compare_models_form").action = action;
if(models.length > 0) {
window.open(action);
return false;
} else {
alert("请先选择欲比较的车型");
return false;
}
}
代码还没贴完,下面继续

解决方案 »

  1.   


    //左边
    var left2_img = '';
    //右边
    var right2_img =
    '<div style="width:180px; text-align:right">' +
    '<form id="compare_models_form" action="http://price.pcauto.com.cn/choose.jsp" onsubmit="return genUrl();">' +
    '<table align="right" border="0" cellspacing="0" cellpadding="0" class="series_sy_dbb">' +
    '<tr>' +
    '<td valign="top" class="series_sy_dbb1">' +
    '<a href="javascript:showOrCloseCompareForm();"><img src="bjk_2.gif" width="24" height="84"></a>' +
    '</td>' +
    '<td valign="top" id="series_sy_db">' +
    '<table id="compare_model_table" border="0" cellspacing="1" cellpadding="0" width="100%">' +
    '<tr>' +
    '<td class="series_sy_dbc1">已选车型�</td>' +
    '</tr>' +
    '<tr id="compare_button_row">' +
    '<td class="series_sy_dbc3">' +
    '<input type="image" src="series_sy_20.jpg" width="64" height="20">' +
    '</td>' +
    '</tr>' +
    '</table>' +
    '</td>' +
    '</tr>' +
    '</table>' +
    '</form>'
    '</div>';
    var delta2 = 0.15
    var collection2;
    function floaters2() {
    this.items2 = [];
    this.addItem2 = function(id2, x, y, content) {
    document.write('<DIV id=' + id2 + ' style="Z-INDEX: 1000; POSITION: absolute;  width:80px; height:60px;left:' + (typeof(x) == 'string' ? eval(x) : x) + ';top:' + (typeof(y) == 'string' ? eval(y) : y) + '">' + content + '</DIV>');
    var newItem2 = {};
    newItem2.object = function() {
    return document.getElementById(id2)
    };
    newItem2.x = x;
    newItem2.y = y;
    this.items2[this.items2.length] = newItem2;
    }

    this.play2 = function() {
    collection2 = this.items2
    setInterval('play2()', 10);
    }
    }
    function play2() {
    for (var ii = 0; ii < collection2.length; ii++) {
    var followObj2 = collection2[ii].object();
    var followObj2_y = (typeof(collection2[ii].y) == 'string' ? eval(collection2[ii].y) : collection2[ii].y);
    var top;
    if (window.innerHeight) {
    top = window.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
    top = document.documentElement.scrollTop;
    }
    else {
    top = document.body.scrollTop;
    }
    if (followObj2.offsetTop != (top + followObj2_y)) {
    var dy = (top + followObj2_y - followObj2.offsetTop) * 0.30;
    dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));
    followObj2.style.top = followObj2.offsetTop + dy;
    }
    // followObj2.style.display2 = '';
    }
    }
    var clientHeight1 = document.body.clientHeight;
    var clientHeight2 = document.documentElement.clientHeight;
    var clientWeigth;
    if(clientHeight2 > 0 && clientHeight2 < clientHeight1) {
    clientWeigth = document.documentElement.clientWidth;
    } else {
    clientWeigth = document.body.clientWidth;
    }
    var thefloaters2 = new floaters2();
    thefloaters2.addItem2('followDiv3',clientWeigth-187, 75, '' + right2_img + '');
    //thefloaters2.addItem2('followDiv2',20,230,''+left2_img+'');
    thefloaters2.play2();

    updateCompareModel();    
    updateCompareForm();
    </script>
    <input type="button" name="aa" value="aa" onclick="addCompareToForm(212,415,'hello world');">
    <div style="height:1000px;"></div>
    </body>
    </html>
    这段代码是实现一个对联广告,但是现在问题是当滚滚动条的时候,滚动条会慢慢变短,而且总是滚不到最下面去,大家帮助看看是什么问题,多谢!