通过PHP和Ajax jQuery从TextArea中呼应短信
HTML:
<div class="mb-3">
<label for="comment" class="form-label">Comments</label>
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>
JavaScript:
let comment = $('textarea.msg').val()
alert(comment);
然后是PHP:
echo $_POST['comment'];
echo isset($_POST['comment']);
echo trim($_POST['comment']) != '';
在这里,Firefox Inspect的网络选项卡中的“响应”选项卡在PHP中没有显示回声命令。我不确定为什么未显示textarea输入hi
因此未插入。
即使对于评论变量的JavaScript警报,我也会得到:
HTML:
<div class="mb-3">
<label for="comment" class="form-label">Comments</label>
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>
javascript:
let comment = $('textarea.msg').val()
alert(comment);
and then PHP:
echo $_POST['comment'];
echo isset($_POST['comment']);
echo trim($_POST['comment']) != '';
Here, the Response tab in Network tab of Firefox Inspect shows nothing for the echo commands in PHP. I am not sure why the textarea input hi
is not shown hence not inserted.
Even for the javascript alert of comment variable, I get this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
克里斯·哈斯(Chris Haas)的学分。
Credits to Chris Haas.
ID在HTML中是唯一的,并且使用jQuery可以更轻松地定位所需的元素。对于课堂,我们使用
$(。&lt; className&gt;)
而对于ID时,我们使用$(#&lt; id_name&gt;)
您的案例>您的案例,
$('#comment ').val()
id is unique in the HTML and with jquery it would be easier to target the element you want. For class we use
$(.<classNAME>)
while for id we use$(#<id_Name>)
Your Case,
$('#comment').val()