最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

using javascript function to render HTML - Stack Overflow

programmeradmin4浏览0评论

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

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

Share Improve this question asked Jul 2, 2013 at 7:45 MayurMayur 2891 gold badge3 silver badges16 bronze badges 7
  • do you need it to be javascript? why not php? – Sergio Commented Jul 2, 2013 at 7:46
  • Why do you want to program it yourself and not use JQuery? – til_b Commented Jul 2, 2013 at 7:48
  • 1 Maybe he just wants to learn, personally I like to do the same – asimes Commented Jul 2, 2013 at 7:49
  • @Sergio : actually i am using PHP as the backend but am not sure if what i want to do can be done using PHP. – Mayur Commented Jul 2, 2013 at 7:49
  • @til_b its a assignment and so hv to use JS only. – Mayur Commented Jul 2, 2013 at 7:50
 |  Show 2 more ments

3 Answers 3

Reset to default 5
html = "<form>....</form>";

document.getElementById("example").innerHTML = html;

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!

Use html tag:

<iframe id="iframeid" ...>

Javascript:

document.getElementById("iframeid").src="url";

http://www.w3schools./tags/tag_iframe.asp

发布评论

评论列表(0)

  1. 暂无评论