PHP 回显 JavaScript
我有一组 PHP 代码,如果用户在文本字段中输入正确的代码,它将在文本字段下方显示一条消息,并出现下一组问题。
但是,我不想在文本字段下方显示消息,而是想知道是否可以在键入正确答案时弹出 jquery 灯箱。
这是我的 PHP 代码,它检测到正确的答案。我将数据存储在数组中:
if (isset($_POST) AND $_POST)
{
foreach ($_POST as $key => $answer)
{
if (preg_match('/task([0-9]+)/i', $key, $matches))
{
$i = $matches[1];
// check answer
if ($data[$i]['answer'] == strtolower(trim($answer)))
{
$i += 1;
$isCorrect = true;
}
$answered = true;
}
}
}
这是在文本字段下方显示消息的代码。
<?php echo ($isCorrect) ? 'That's correct!' : ''; ?>
这是我想要集成的 jQuery lightbox 代码。
<script type="text/javascript">
$().ready(function() {
$("#dialog").jqm();
});
</script>
<div class="jqmWindow" id="dialog">
<a href="#" class="jqmClose">Close</a>
That's correct!
</div>
有人帮忙吗?
I have a set of PHP code where if user key in the correct code in the text field, it will display a message below the text field and the next set of question comes out.
However, instead of displaying a message below the text field, I would like to know whether it is possible to have a jquery lightbox popup upon keying in the correct answer.
Here's my PHP code where it detects the correct answer. I store my data in an array:
if (isset($_POST) AND $_POST)
{
foreach ($_POST as $key => $answer)
{
if (preg_match('/task([0-9]+)/i', $key, $matches))
{
$i = $matches[1];
// check answer
if ($data[$i]['answer'] == strtolower(trim($answer)))
{
$i += 1;
$isCorrect = true;
}
$answered = true;
}
}
}
And here's the code where it displays message below the text field.
<?php echo ($isCorrect) ? 'That's correct!' : ''; ?>
Here's the jQuery lightbox code I want to integrate in.
<script type="text/javascript">
$().ready(function() {
$("#dialog").jqm();
});
</script>
<div class="jqmWindow" id="dialog">
<a href="#" class="jqmClose">Close</a>
That's correct!
</div>
Help, anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 AJAX 将答案发布到 PHP 脚本。在 Ajax 成功回调中,使用适当的文本触发对话框。完毕!
Use AJAX to POST the answer to your PHP script. In the Ajax success callback, trigger the dialog box with the appropriate text. Done!