gpt4 book ai didi

javascript 函数在 php 中无法正常工作

转载 作者:行者123 更新时间:2023-12-01 03:30:12 26 4
gpt4 key购买 nike

这是我的 php 代码。插入数据后,我使用警报消息。消息正确显示。但当我点击 x 十字符号时它不会关闭。

if(isset($_POST['create_post'])){

$name = $_POST['name'];
$email = $_POST['email'];
$country = $_POST['country'];
$msg = $_POST['description'];



$stmt = $connection->prepare("INSERT INTO message(name,email,country,msg,date) VALUES (?, ?, ?, ?,now())");
$stmt->bind_param('ssss', $name,$email,$country,$msg);
$stmt->execute();
$stmt->close();

if($stmt){

echo '<div class= "alert">';
echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">&times;</span> ';
echo 'Your messaage has been sent ';
echo ' </div>';

}else{
die('Query fialed' . mysqli_error($connection));
}

}

警报消息部分:

echo '<div class= "alert">';
echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">&times;</span> ';
echo 'Your messaage has been sent ';
echo ' </div>';

最佳答案

该行嵌套太多 "标记:

echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">&times;</span> ';

如果你正确地转义内部的( \" ),它就会起作用。

使用原始 HTML 的 Fiddle 示例:https://jsfiddle.net/myingling/3vv7jLd4/

更好的是,我只需删除 echo语句,所以它看起来像这样:

if($stmt){
?>

<div class= "alert">
<span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span>
Your messaage has been sent
</div>
<?php
}else{

关于javascript 函数在 php 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44575090/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com