2014-04-11 35 views
3

我做的,被調用的缺乏從頁面更好的詞的功能,讓稱它爲第1頁,單擊一個按鈕,當函數被調用,以表示函數結束它會調用另一個創建(或應該看到我無法測試它)html並將其附加到具有#lista id的div。製作功能在另一個頁面影響因素

問題是,這個div是另一個頁面(Page2),所以我不知道是否有像ajax這樣的語法,你指定你想要這些值去的地方,所以基本上頁1調用一個函數(上以防萬一),另一個文件中的函數調用另一個和函數的結果,以防萬一)

這裏去第一頁上(另一個文件,又是我的jQuery/JS代碼來進一步說明:

$("#btnAceptar").click(function() { 
    var idlab = $('#txtNumLab').val(), 
    capacidad = $('#txtCapacidad').val(), 
    carrera = $('#txtCarrera').val(), 
    ubicacion = $('#txtUbicacion').val(); 


    var request = $.ajax({ 
    url: "includes/functionsLabs.php", 
    type: "post", 
    data: { 

    'call': 'addLab', 
    'pIdLab':idlab, 
    'pCapacidad':capacidad, 
    'pCarrera':carrera, 
    'pUbicacion':ubicacion}, 

    dataType: 'json', 

     success: function(response){ 
     alert('exito') 

    agregar();   

    } 
    }); 
}); 

此函數應該會影響第2頁上的id爲#Lista的元素。

function agregar(){ 

var div = $("#lista").append("<div class='box'> 
      <p>Lab #'numero'</p>         
      <p class='info'><a href='#' id='lnkInfo'>Info</p></a> 
      <p class='info'><a href='reservarLab.html'>Reservar</p></a> 
     </div>"); 



div.id = querySelectorAll('#lista > div').length +1; 
var numero = div.id; 
$('#numero').append(div); 


} 

非常感謝!

+0

另一頁面作爲在其他標籤/窗口,或在一個頁面,用戶最終將導航到? –

+2

可能重複:http://stackoverflow.com/questions/7709289/how-to-pass-javascript-object-from-one-page-to-other –

+0

@PatrickEvans,另一頁是另一個文件中的函數調用上Page1.php,第二個函數是爲了影響Page2.php中的元素。這兩者都在同一個文件夾中,並且是同一整體的一部分。 –

回答

1

是的,你可以使用jQuery獲取其它頁面內容:

Ajax請求得到整個文件,但一旦它的檢索可以過濾內容:

$.ajax({ 
    url:href, 
    type:'GET', 
    success: function(data){ 
     $('#content').html( $(data).find('#IDofDivToFind')); 
    } 
}); 

第二種方法(未經測試)

您可以使用jQuery .load()方法:

$("#content").load("ajax/test.html div#content"); 

參考:

http://api.jquery.com/load/

相關問題