我有一個 div,其中使用 javascript 填充了 XML 內容。目前,我希望使用按鈕刷新“displayCode”div 內容。codeContainer是displayCode的容器。目前,代碼將整個 html 頁面刷新到 div 中,而不僅僅是刷新頁面時獲得的內容。我已經嘗試過在線的所有其他方法,它們都返回一個空白 div 或將整個頁面復制到 div 中。是的,我在標題中命名了 jQuery。tl;dr:為什么我的 .load 不工作?當前代碼:<body><script>function buttontest() { alert('pressed') $('#displayCode').load('index.html #displayCode');};</script><button onclick="buttontest()">Click me</button><div id = "codeContainer"><div id='displayCode'></div><br></div>
1 回答

慕容3067478
TA貢獻1773條經驗 獲得超3個贊
好的,首先type="button"
按鈕上應該有一個,因為默認type
是submit
//I Applied the click Listener on the id rather than having a function <button id="loadContent" type="button">Click me</button>
,并且您想確保您擁有.min.js
jquery 版本而不是.slim.min.js
版本,因為它沒有 AJAX (希望這是有意義的)。這可能不是必需的,但我認為您不需要target
內容load
。所以
$("#displayCode").load("./index.html"); // Adjust the file path accordingly
應該做的。除此之外,你應該表現得很好。
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報
0/150
提交
取消