Buttons 標籤對於 Jquery Attr 的工作至關重要
P粉141035089
P粉141035089 2024-02-04 11:27:56
0
1
538

atrr 函數沒有給出所需的回應,我有一個小程式碼,可以從外部 API 中取得數據,該 API 在 dict 中有幾個數據。

<div id="facet-knowledge-panel" style="margin-left: 70px;">
        <h2 id="facet_panels_title"></h2>
        <div id="facet_panels_content"></div>
    </div>

    <button id="open">open</button>
 
    <script>
        let facet_kp = "http://localhost/render-to-html?facet_tag=category&value_tag=en:beers";

        fetch(facet_kp)
            .then((response) => {
                if (response.ok) {
                    return response.text();
                }
                else {
                    throw new Error("Network Response Error while fetching facet kp");

                }
            })
            .then(data => {
                let title = document.getElementById("facet_panels_title");
                title.innerHTML = "Facet knowledge panel";

                let knowledgepanel = document.getElementById("facet_panels_content");
                knowledgepanel.innerHTML = data;
            })
    </script>

在這裡,id="facet_panels-content"將從API獲取數據後返回數據,它包含“<details><summery>......”標籤中的數據,但我想默認情況下保持詳細資訊標籤打開。

<script>
        $(document).ready(function(){
          $("#open").click(function(){
            $("#HungerGames").attr("open",true);
          });
        });
</script>

我正在使用 Jquery 程式碼透過按鈕打開單個詳細資料標籤,它工作正常,但我想讓它預設打開,無需任何按鈕。

$(document).ready(function(){
            $("#HungerGames").attr("open",true);
        });

所以,如果我使用它,它不會打開該 id 的「詳細資料」標籤。我希望預設保持“詳細資料”標籤打開,不帶任何按鈕。

P粉141035089
P粉141035089

全部回覆(1)
P粉551084295

#HungerGames 選擇器與 HTML 中的任何元素都不符。

所以大概這個操作是將其加入到頁面中? :

knowledgepanel.innerHTML = data;

顯然,在該元素添加到頁面之後之前,您無法與該元素進行互動。因此,不要嘗試在頁面加載時顯示該元素,而是在將其添加到頁面時顯示它:

knowledgepanel.innerHTML = data;
$("#HungerGames").attr("open",true);
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!