Javascript 在php代码中插入jquery
如何将此代码放入我的程序中的注册代码中,如果注册成功,将弹出此代码??我是jquery的新手,所以我不知道如何做这件事……请帮帮我Javascript 在php代码中插入jquery,javascript,php,jquery,Javascript,Php,Jquery,如何将此代码放入我的程序中的注册代码中,如果注册成功,将弹出此代码??我是jquery的新手,所以我不知道如何做这件事……请帮帮我 <script> $(document).ready(function() { // show a dialog box when clicking on a link $("#success").on('click', function(e) { e.preventDefault(); $.Zebra_Dialo
<script>
$(document).ready(function() {
// show a dialog box when clicking on a link
$("#success").on('click', function(e) {
e.preventDefault();
$.Zebra_Dialog('<strong>Congratulations </strong>' +
'You are now successfully registered!');
});
});
</script>
$(文档).ready(函数(){
//单击链接时显示对话框
$(“#成功”)。在('click',函数(e){
e、 预防默认值();
$.Zebra_对话框(“祝贺您””+
“您现在已成功注册!”;
});
});
以下是我的php代码:
<?php
if(isset($_POST['save'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$position = $_POST['position'];
$username = $_POST['username'];
$password = $_POST['password'];
$dateregistered = date("Y-m-d H:i:s");
if (!$_POST['fname'] || !$_POST['lname'] || !$_POST['position'] || !$_POST['username'] || !$_POST['password'] ) {
echo "You did not complete all of the required fields!";
} else {
$query="INSERT INTO users (position, fname, lname, username,password,dateregistered) VALUES ('$position','$fname','$lname','$username','$password',CURRENT_TIMESTAMP) ";
mysql_query($query);
if($query)
echo "You Successfully Created an Account!";
}
}
?>
追加jquery函数是您的php代码
<?php
if(isset($_POST['save']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$position = $_POST['position'];
$username = $_POST['username'];
$password = $_POST['password'];
$dateregistered = date("Y-m-d H:i:s");
if (!$_POST['fname'] || !$_POST['lname'] || !$_POST['position'] || !$_POST['username'] || !$_POST['password'] )
{
echo "You did not complete all of the required fields!";
}
else
{
$query="INSERT INTO users (position, fname, lname, username,password,dateregistered) VALUES ('$position','$fname','$lname','$username','$password',CURRENT_TIMESTAMP) ";
mysql_query($query);
if($query){
echo "You Successfully Created an Account!";
// append here your jquery code
?>
<script>
$(document).ready(function() {
// show a dialog box when clicking on a link
$.Zebra_Dialog('<strong>Congratulations </strong>' +
'You are now successfully registered!');
});
</script>
<?php
}
}
}
//corrected indentation
?>
您只需使用
echo "<script>alert('You Successfully Created an Account!')</script>";
echo“警报('您成功创建了帐户!')”;
试着这样做:
if($query)
{
?>
<script>
$(document).ready(function() {
$.Zebra_Dialog('<strong>Congratulations </strong>' +
'You are now successfully registered!');
});
</script>
<?php
}
if($query)
{
?>
$(文档).ready(函数(){
$.Zebra_对话框(“祝贺您””+
“您现在已成功注册!”;
});
**试试这个代码**
嗯,最简单的解决方案是回显jQuery代码。@YUNOWORK是几乎唯一的解决方案……嗯,用PHP向DOM添加代码没有太多的可能性。^^我想您可以使用DOMDocument,但这只需要一个小文本框就太多了。在我看来,使用AJAX调用和成功回调后,显示弹出窗口()…您也可以使用$\u会话
没问题,伙计,下次检查一下,我本打算给出这个答案,但您是第一个
**Try this code.......**
<?php
if(isset($_POST['save']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$position = $_POST['position'];
$username = $_POST['username'];
$password = $_POST['password'];
$dateregistered = date("Y-m-d H:i:s");
if (!$_POST['fname'] || !$_POST['lname'] || !$_POST['position'] || !$_POST['username'] || !$_POST['password'] )
{
echo "<script>
$(document).ready(function() {
$('#success').on('click', function(e) {
e.preventDefault();
$.Zebra_Dialog('<strong>Congratulations </strong>' +
'You did not complete all of the required fields!');
});
});
</script>";
}
else
{
$query="INSERT INTO users (position, fname, lname, username,password,dateregistered) VALUES ('$position','$fname','$lname','$username','$password',CURRENT_TIMESTAMP) ";
if(mysql_query($query)){
echo "<script>
$(document).ready(function() {
$('#success').on('click', function(e) {
e.preventDefault();
$.Zebra_Dialog('<strong>Congratulations </strong>' +
'You Successfully Created an Account!');
});
});
</script>";
}
}
}
?>