Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

javascript - HTML / JavaScript更改div内容(HTML/Javascript change div content)

I have simple HTML code with some javascript, it looks like:(我有一些JavaScript的简单HTML代码,如下所示:)

<html> <head> <script type="text/javascript"> function changeDivContent() { // ... }; </script> </head> <body> <input type="radio" name="radiobutton" value="A" onClick="changeDivContent()"> <input type="radio" name="radiobutton" value="B" onClick="changeDivContent()"> <div id="content"></div> </body> </html> I just wanted to be able to change the div's content (it's inner html) with selecting one of "A" or "B" radio buttons, but div#content does not have javascript attribute "value", so I am asking how it can be done.(我只是想能够通过选择“ A”或“ B”单选按钮之一来更改div的内容(它是内部html),但是div#content没有javascript属性“ value”,所以我问它如何完成。)   ask by Rob translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

假设您没有使用jQuery或其他使您更轻松地进行此类操作的库,则可以只使用元素的innerHTML属性。

document.getElementById("content").innerHTML = "whatever";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...