2012-12-13 182 views
1

我需要動態更改我的網站中的塊引用內容。 我實際上必須檢索我需要從數據庫中顯示的內容,所以我需要使用一個php腳本來獲取它們並以我需要的方式形成它們。動態更改塊引用的內容

我試圖用類似的東西: http://dhtmlexamples.com/2011/02/18/dynamically-loading-content-using-ajax-and-xmlhttprequest/

但沒有成功:/

我應該說,我BLOCKQUOTE具有HTML它雖然我不認爲它很重要。

有人能給我一些幫助嗎?

編輯:下面是一些代碼

<blockquote class="pro-in" id="content" style="left:-10000px; opacity:0;"></blockquote> 

當我點擊一個圖像塊引用獲得在可見的「平面」繼續前行。內容是用init()生成的;功能。在上面提供的鏈接中描述了init函數和邏輯。建議以後

//修正功能,從下面的答案 - 使用JQuery 功能openpro(contentNumber){

$.get('phpscripts/projectsLogic.php?project='+contentNumber, function(data) { 
     $('#content').html(data); 
    }); 

    $('#content').animate({left:0, opacity:1},{duration:1600}); 
    $('#con').animate({left:-10000, opacity:0},{duration:1600}); 
} 

如果您對實際創建的內容,而不是固定這種解決方案我是一個更好的建議爲它。 ------------------------------------- bxslider EDIT2:

我實際上稱之爲是一個bxslider(加上其他人)。問題是,我以前在$(文件)來初始化bxsliders。就緒這樣調用:

$(document).ready(function(){ 
    $('.bxslider').bxSlider({ 
     pager: true, 
     auto: true, 
     speed: 2000, 
     autoHover: true, 
     pause: 6000 
    }); 
    $('.bxslider1').bxSlider({ 
     pager: true 
    }); 
    $('.bxslider2').bxSlider({ 
     pager: true 
    }); 
    .... 
    }); 

當我動態改變div的內容,我想沒有bxlider對象處理的新內容,所以沒有可見的滑塊。我試着把這些調用放在創建內容的函數中(openpro()),但徒勞無功。我也試過這樣的事情:

var slide = document.createElement("script"); 
     slide.type = "text/javascript"; 
     slide.text = "$(document).ready(function(){ $('#slider1').bxSlider({pager:true}); });"; 

     document.head.appendChild(slide); 

但仍然沒有成功。有沒有人有任何想法?對不起,我剛開始使用Web開發語言,所以我有點頭緒..

+0

請穿上您的代碼,而不是一些外部示例。我們無法幫助我們看不到的東西。 –

回答

2

嘗試這個例子用jQuery得到

testFunction(「lorem.txt」,「內容」); //第一個參數是文件url,第二個參數是blockquote ID

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script> 
function testFunction(path, container){ 
    $.get(path, function(data) { 
     $('#'+container).html(data); 
    }); 
    $('#'+container).animate({left:0, opacity:1},{duration:2000}); 
    $('#'+container).animate({left:-10000, opacity:0},{duration:2000}); 
} 

</script> 
<body onload="testFunction('lorem.txt', 'content');"> 
    <blockquote class="pro-in" id="content" style="left:-10000px; opacity:0;"></blockquote> 
</body> 
+0

它的工作謝謝你!問題是,在我所說的,實際上是一個bxslider。爲了使用它,我必須做一個這樣的調用: $(document).ready(function(){('。bxslider'+ contentNumber).bxSlider({0121}pager:true; }); 這意味着我調用的滑塊沒有爲它們準備好這個對象,我嘗試在調用內容更改的函數中執行此調用(在您的示例中爲testFunction),但它不起作用:/ – STE