![](/img/trans.png)
[英]How can i get the output of javascript object in div tag using document.write?
[英]How can I write output with javascript?
我用代碼創建了一個jsfiddle,該代碼旨在用存儲在按鈕中的字符串替換段落中的字符串。 據我所知,這是正確的。 但是我無法正常工作。 有人可以指出我的錯誤嗎?
<p id="arbitraryIdentification">Product information</p>
<button onclick="document.getElementByID('arbitraryIdentification').innerHTML = 'this text just replaced the original text'">text swaperizer</button>
您需要將ID括在引號和getElementById
(而不是ID)
看一下函數document.getElementById
。
通過元素ID返回對該元素的引用; ID是一個字符串 ,可用於標識元素
因此,您的正確代碼將是:
document.getElementById('unique-key-here')
'getElementByID'應該是' getElementById '('Id'而不是'ID')
<button onClick="document.getElementById('arbitraryIdentification').innerHTML = 'this text just replaced the original text'"> </button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.