该脚本在一侧有效,但在另一侧无效。它得到一个未捕获的类型错误:无法调用未定义的方法“打开”。脚本放在两边的同一个位置...
此代码用于根据用户选择向 db 1-5 发送评级。
function send_ajax(bewertung, click) {
if (click) {
alt = userrating[{TOPIC_ID}];
userrating[{TOPIC_ID}] = bewertung;
xmlhttp.open("GET", "bewertung.php?{BEWERTUNGSVAR}&wertung=" + bewertung, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function () {
var a = new Date();
a = new Date(a.getTime() + 1000 * 60 * 60 * 24 * 365);
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText) {
document.getElementById("ratingdesc").innerHTML = "{L_RATINGCOUNTED}";
} else {
userrating[{TOPIC_ID}] = alt;
document.getElementById("ratingdesc").innerHTML = "Bewertung fehlgeschlagen... bitte nochmals versuchen!";
}
}
}
} else {
if (bewertung) {
document.getElementById("ratingstarbg").style.backgroundPosition = "0 -" + (bewertung * 17) + "px";
} else {
if (typeof userrating[{TOPIC_ID}] == 'undefined') {
document.getElementById("ratingstarbg").style.backgroundPosition = "0 -{STARTBGPOS}px";
} else {
document.getElementById("ratingstarbg").style.backgroundPosition = "0 -" + (userrating[{TOPIC_ID}] * 17) + "px";
}
}
}
}
这就是它在 HTML 中的调用方式
<div style="float:left">
<span id="ratingstarbg" class="star" style="background-position: 0 -{STARTBGPOS}px">
<a class="ratestar" href="javascript:send_ajax(1,true);" onmouseover="javascript:send_ajax(1,false);" onmouseout="javascript:send_ajax(0,false);"></a>
<a class="ratestar" href="javascript:send_ajax(2,true);" onmouseover="javascript:send_ajax(2,false);" onmouseout="javascript:send_ajax(0,false);"></a>
<a class="ratestar" href="javascript:send_ajax(3,true);" onmouseover="javascript:send_ajax(3,false);" onmouseout="javascript:send_ajax(0,false);"></a>
<a class="ratestar" href="javascript:send_ajax(4,true);" onmouseover="javascript:send_ajax(4,false);" onmouseout="javascript:send_ajax(0,false);"></a>
<a class="ratestar" href="javascript:send_ajax(5,true);" onmouseover="javascript:send_ajax(5,false);" onmouseout="javascript:send_ajax(0,false);"></a>
</span>
</div>