2016-08-02 57 views
1

我正在使用healcode在我的網站上顯示mindbody數據。我正在使用healcode小部件,問題是我只能更改CSS而不是觸摸HTML小部件將數據提交到表中,這對我的需求非常有限。我希望能夠創建html結構,或者至少可以操縱當前的結構。使用javascript從表格中提取數據

是否可以使用CSS或Javascript或兩者來從表中提取內容和數據並重新創建我選擇的HTML結構?

+0

您可以使用JavaScript循環訪問DOM並以不同的格式顯示它,但有可能找到數據來自哪裏並從源代碼獲取它? –

+0

@DaveChen你的意思是一個API? – user2684452

+0

可能有庫更容易訪問DOM,但您可以使用vanilla JavaScript來[訪問DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction)。 –

回答

1

當然,你可以通過JavaScript來做到這一點,雖然這是一個相當廣泛的問題。你必須得到你需要操作的表格元素(比如說,如果它有,並且id爲someId,則必須使用var table = document.getElementById('someId');),然後使用DOM API操作其table.innerHTML(或許是一個很好的起點)或其子節點:比方說this page(「參數值」表),您可以嘗試在瀏覽器控制檯:

// first table with the "w3-table-all notranslate" class 
var table = document.getElementsByClassName("w3-table-all notranslate")[0]; 

table 
    .children[0] // will get the tbody element 
    .children[1] // will get the second row from the tbody element 
    .children[0] // will get the first (colomn) cell in the second row 
    .innerHTML; // will show you html contents of the cell in the console 

// change the cell contents 
table.children[0].children[1].children[0].innerHTML = "<b>I've changed this stuff!</b>"; 

// you may also want to remember rows/cells: 
var row = table.children[0].children[1]; 
var cell = row.children[0]; 

,基本上就是這樣。

相關問題