簡體   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