使用javascript函数来呈现HTML [英] using javascript function to render HTML
问题描述
我有一个静态页面,它有 login
和注册
链接。我希望当用户点击 Login
,它调用 Javascript
函数,该函数依次显示登录表单$ c $尽管我可以在
document.write()
中嵌入整个HTML标签,但是,这是非常混乱,肯定不是长的HTML代码的最佳做法。
那么我怎样才能将HTML代码嵌入到JS函数?我如何控制在页面上定位表单。
我正在寻找一个Javascript解决方案,而不是JQuery
因此,对于HTML,您可以使用类似这样的内容
< div id =regElementsstyle =display:none; class =registration>注册表单元素< / div>
< input type =buttonname =reonclick =showReg()/>
对于Javascript,您只需使用这个函数
function showReg(){
document.getElementById(regElements)。style.display =;
}
你可以在任何地方找到这个代码的例子!祝你好运!
I have a static page that has login
and registration
link.I want that when a user clicks on Login
,it calls a Javascript
function that in turn displays the Login Form
on the same page.
Although I can embed the whole HTML tag in document.write()
but that is very messy and am sure is not the best practice for long HTML codes.
So how can i embed HTML codes into the JS function?and how do i control the positioning of the form on the page.
I am looking for a Javascript solution only and not JQuery
Try to make a div containing your elements for the registration So for HTML you can use something like this
<div id="regElements" style="display:none;" class="registration" >Elements for a registration form</div>
<input type="button" name="re" onclick="showReg()" />
And for Javascript you just use ths function
function showReg() {
document.getElementById("regElements").style.display = "";
}
You can find examples of this code everywhere! Good luck!
这篇关于使用javascript函数来呈现HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!