本文介绍了javascript里面的Html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Javascript中使用一些html标签。但是,Html标签不起作用。我如何在javascript中使用html标签。我想在Javascript中使用h1标签但不起作用:(
I am trying to use some html tag inside Javascript.But, Html Tag does not work. How can i use html tag inside javascript. I wanted to use h1 tag inside Javascript but did not work:(
<script type="text/javascript">
if(document.getElementById('number1').checked) {
<h1>Hello member</h1>}
</script>
推荐答案
您将要么 document.write
它或使用文档对象模型:
You will either have to document.write
it or use the Document Object Model:
<script type="text/javascript">
if(document.getElementById('number1').checked) {
document.write("<h1>Hello member</h1>");
}
</script>
使用示例
Example using DOM
<h1></h1> <!-- We are targeting this tag with JS. See code below -->
<input type="checkbox" id="number1" checked /><label for="number1">Agree</label>
<div id="container"> <p>Content</p> </div>
<script type="text/javascript">
window.onload = function() {
if( document.getElementById('number1').checked ) {
var h1 = document.createElement("h1");
h1.appendChild(document.createTextNode("Hello member"));
document.getElementById("container").appendChild(h1);
}
}
</script>
这篇关于javascript里面的Html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!