リクエスト時にdivを折りたたんでみようとしていますが、setTimeout関数がコールバック関数を正常に呼び出せません。ここでは以下のコードです:なぜこのsetTimeoutコールバックでエラーが出るのですか?
function newsFeed() {
this.delete = function(listingID) {
var listing = document.getElementById(listingID);
var currHeight = listing.offsetHeight;
var confirmDelete = confirm("Are you sure you'd like to delete this listing forever?");
if (confirmDelete) {
this.collapse(listingID,currHeight,currHeight,100);
}
}
this.collapse = function(listingID,orig_height,curr_height,opacity) {
var listing = document.getElementById(listingID);
var reduceBy = 10;
if(curr_height > reduceBy) {
curr_height = curr_height-reduceBy;
listing.style.overflow = "hidden";
listing.style.height = (curr_height-40) + "px";
if(opacity > 0) {
opacity = opacity - 10;
var opaque = (opacity/100);
listing.style.opacity=opaque;
listing.style.MozOpacity=opaque;
listing.style.filter='alpha(opacity='+opacity+')';
}
setTimeout("this.collapse('"+listingID+"',"+orig_height+","+curr_height+","+opacity+")",1);
}
}
}
var newsFeed = new newsFeed();
は、次のように私は、文書でそれを呼び出す:
<div id="closeMe">
<a onclick="newsFeed.delete('closeMe');">close this div</a>
</div>
それはthis.collapse内setTimeout関数になると...それエラー「this.collapse関数ではありません "。
私はこれをnewsFeed()またはthis.collapse関数内に入れますか?別名...実際には「これ」を参照すべきですか? – johnnietheblack
...申し訳ありませんが、私はself.collapseを取得しているため、関数ではありません – johnnietheblack
あなたはそれを持っていますあなたは – johnnietheblack