我需要能够在 JavaScript 中创建一个函数,我需要做的就是输入 h1("hello"),它就会打印 hello。
我想避免这种方法:
function h1(text) {
document.write('<h1>'+text+'</h1>');
}
这就是我所拥有的:
function h1(text) {
var div = document.createElement('div');
document.appendChild(div);
var h1 = document.createElement('h1');
div.appendChild(h1);
h1.createTextNode(text);
}
<script>
function myFunction(text) {
var h = document.createElement("H1");
var t = document.createTextNode(text);
h.appendChild(t);
document.body.appendChild(h);
}
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)