繁体   English   中英

PHP / JavaScript如何将2页合二为一

[英]PHP/JavaScript How to combine 2 page in one

我需要有关如何使2页成为一页的参考。

本来我有2 PHP页面。 View.php和comment.php

view.php将具有一个调用comment.php的链接。 当单击“评论”链接时,它将像弹出一样打开comment.php。 填写评论后,单击发送,它将关闭并返回view.php。

问题是,我希望它隐藏起来而不是弹出窗口,直到我单击它为止。 我不知道这个过程的确切用语是什么。 我知道它与javascript有关,使用id,onclick函数和类似于frame函数。 因为我不知道它叫什么,所以我很难研究。 所以任何人都请告诉我它的名字或给我任何有关如何执行的参考或示例解决方案。

非常感谢你

更新:

亲爱的大家..

在互联网上找到此代码。 就像RageZ所说的..它使用CSS和JavaScript来显示和隐藏img。 如何为他人使用?

我需要将我的comment.php转换为一个函数并放入view.php中吗?请对该函数使用id。 可能吗?

<html>
<head>
<script>
function changeme(id, action) {
       if (action=="hide") {
            document.getElementById(id).style.display = "none";
       } else {
            document.getElementById(id).style.display = "block";
       }
}
</script>

</head>
<body>
<img id="myIMG" style="display: none;" src="question.php.html"width="100" height="100" />
<span onclick="changeme('myIMG', 'show');" style="color: blue; text-decoration: underline; cursor: pointer;">Show the image</span>
<span onclick="changeme('myIMG', 'hide');" style="color: blue; text-decoration: underline; cursor: pointer;">Hide the image</span>
</body>
</html>

我认为您正在寻找的是Greybox之类的东西吗?

它会在页面顶部打开一个新的pag,而不是打开一个弹出窗口,您最好查看一下示例,它们比我在这里说的要清楚得多。

您可以使用以下方法来执行所描述的过程:

view.php

<script language="JavaScript">

function openComment(id) // Open comment.php in a new window and send the id of the thing you want to comment
{
    window.open('comment.php?id='+id, '_blank');
}

</script>

<a href="#" onClick="openComment(1)">Comment</a>

comment.php

<?php
    if ( isset($_POST['msg']) && intval($_POST['id']) > 0 ) // If a comment is sent and the id is a number > 0
    {
        /* Write your message to db */
?>
<!-- Reload the underlying window and close the popup -->
<script language="JavaScript">
window.parent.reload();
window.close();
</script>
<?php
    }
    else // Show the Form to post a comment
    {
?>
<form name="comment" action="comment.php" method="POST">
<input type="hidden" name="id" value="<?php echo $_GET['id'] ?>" />
<input type="text" name="msg" value="Input your comment here" />
<input type="submit" value="Submit" />
</form>
<?php } ?>

您可以使用Ajax / DHTML进行弹出并将数据发布到同一页面中的服务器。

我认为您需要一个框架来快速完成操作,因此有很多javascript框架:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM