dpauxqt1281 2015-03-03 03:57
浏览 78
已采纳

将HTML输入到包含的索引页面

I am trying to improve an old website which has been created by having one index.php

Which is behaving like a parent to several sub sites which then insert their specific contents into the parent using javascript (getElement, add all sorts of content and then appendChild).

This results in a huge code to just create a little form, which can be done far neater with HTML.

Thus my question;

how can I input HTML content into a parent file's elements without creating these contents all with javascript?

I am looking for a solution like:

<?php
include_once('index.php');
?>
<ul id="nav">
    <li class="navi"><a href="processlogout.php">Log uit</a></li>
</ul>
<script>
somehow insert newly created unsorted list "nav" into the included index.php
</script>

I hope I have formulated my question clearly and am looking forward to your answers!

  • 写回答

2条回答 默认 最新

  • dongzi5673 2015-03-09 08:27
    关注

    I have found what I was looking for, it was innerHTML
    This way I can simply type an HTML code inside javascript which is then inputted into the included php as I wanted.
    Example;

    document.getElementById('databox').innerHTML = 
    '<div class = "selectform">' +
        '<form id="login" method="post" action="requestklant.php">' +
            '<select name="klantdropdown"></select>' +
            '<button type="submit">Opvragen</button>'+ 
      '</form>' +
    '</div>';
    

    Thank you for your suggestions and effort, though.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部