0

一直在尝试让这个工作。我想要的是,当用户单击create Card表单时应该弹出多个字段,以便他们可以查看$key[2]和编写问题和答案。

如果有人能指出我正确的方向来使用 javascript 创建这个表单并解释如何将变量从该表单返回到 php,那就太棒了。我正在尝试使用xmlhttprequest,我不知道这是否最好。

<?php
if (isset($myNotes)) {
    foreach ($myNotes as $key) {
        Print "<li>$key[2] <a href=''><dif onclick='createCard()'>(Create Card)</dif></a></li>";
    }
}
?>
function createCard()
{
    xmlhttp=new XMLHttpRequest();
    var question;
    var answer;

    question=prompt("Enter Q:","");
    answer=prompt("Enter Answer:","");

    xmlhttp.open("GET","control.php?q="+question, true);
    xmlhttp.send();
}
4

1 回答 1

0

您可以有一个隐藏的 Div,其中包含当用户单击 createCard 时显示的表单。

<div id="popupdiv" style="display:none">
<p>Question: <input type="text" id="question"></p>
<p>Answer: <input type="text" id="answer"></p>
<input type="button" onclick="processCard()">
</div>



function createCard(){

    // This displays the popup with your form.
    document.getElementById("popupdiv").style.display = "block";
}

function processCard(){

    // This grabs the data and sends it server and then hides the div again.
    var question = document.getElementById("question").value;
    var answer = document.getElementById("answer").value;
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("GET","control.php?q="+question+"&a="+answer, true); 
    xmlhttp.send();
    document.getElementById("popupdiv").style.display = "none";
}   




 <?php
 $question = $_GET['question'];
 $answer = $_GET['answer'];
 ?>
于 2012-07-28T21:11:42.857 回答