簡體   English   中英

當從另一個頁面獲取元素ID值時,jQuery Load()返回[object object]

[英]Jquery Load() returns [object object] when fetch element id value from another page

我正在從mysql查詢結果page.php獲取值到display.html。 我可以在div ID中的display.html中顯示“ VALUE368”值。 但我也想在Firebase實時數據庫中記錄“ VALUE386”,為此,我正在嘗試使用以下代碼。

$(document).ready(function (){
  function testing(){
    return $('#VALUE368').load('data.php #VALUE368');
    //return 100 + 300 ;
  } 
  var tag1 = testing();
  document.write(JSON.stringify(tag1));
  console.log(tag1);
}); 

我也嘗試使用var tag1 = document.getElementById("VALUE386"); 但它返回空值。

請幫助我。

問題是因為load()返回一個包含#VALUE368元素的jQuery對象。 這就是為什么在調用stringify()時看到[object Object]原因。

除此之外,您的邏輯很奇怪。 您正在調用document.write (這本身就是一種不好的做法),試圖將內容寫入DOM( load()已經為您完成load()

您可以簡單地將代碼更改為此:

$(document).ready(function() {
  $('#VALUE368').load('data.php #VALUE368');
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM