gpt4 book ai didi

javascript - 我的其他表格没有提交

转载 作者:行者123 更新时间:2023-11-30 21:17:38 27 4
gpt4 key购买 nike

所以我创建了一个页面来为数据库中的每个聊天打印出一个 div,并且每个聊天都有一个附加的表格。当我点击表单时,表单被提交并显示无输入,并且它的值被发送到 php 来做其他事情。现在的问题是,即使代码是相同的,也只有第一个 div 的表单被提交。表单就在 div 上,并且是绝对显示的。这两种形式是相同的,但我需要两者都工作并获得相同的 php 代码。代码:HTML

<div class="chaty">
<form method="post" action="index.php" name="chat_lox" id="chat_loc">
<input type="text" name="chat_locy"
value="5e2dbe2be3b5927c588509edb1c46f7d">
</form>
<div class="chatDesc" id="84281145">
<div class="tit">Creator: </div>
<div class="iriss"><i id="close_chatn" onclick="closeChat(84281145)"
class="material-icons">close</i></div>

<form action="mypage.php" method="post">


<div class="authr_name"><button value="John Brown" name="userlink"
class="subm_as_text">Hitsuji</button></div>
</form>
<div class="titd"><h3>Description</h3></div>
<div class="description_chat">jaames</div>
</div>


<span onclick="openChat(84281145)">☰</span>
<div class="chatname"><h3>james</h3></div>
<div class="chatback"></div>
<div class="underlie"><p>Users: 1</p><p> Created: 2017/07/28 07:09:40pm</p>
</div>

</div>
<!-- one that doesn't work -->
<div class="chaty">
<form method="post" action="index.php" name="chat_lox" id="chat_loc">
<input type="text" name="chat_locy"
value="9503e253936e716f18d9c57b4f97d618">
</form>
<div class="chatDesc" id="6179276">
<div class="tit">Creator: </div>
<div class="iriss"><i id="close_chatn" onclick="closeChat(6179276)"
class="material-icons">close</i></div>

<form action="mypage.php" method="post">


<div class="authr_name"><button value="Hitsuji" name="userlink"
class="subm_as_text">Hitsuji</button></div>
</form>
<div class="titd"><h3>Description</h3></div>
<div class="description_chat">The Army of JOhn</div>
</div>


<span onclick="openChat(6179276)">☰</span>
<div class="chatname"><h3>John Army</h3></div>
<div class="chatback"></div>
<div class="underlie"><p>Users: 2</p><p> Created: 2017/07/23 11:31:06am</p>
</div>

</div>

JS

$("#chat_loc").on("click",function() {
$(this).submit();
alert("submitted");

});

PHP

if(isset($_POST['chat_locy']) ? $_POST['chat_locy'] : null){echo "it 
worked";}

最佳答案

您一次只能提交一份表格。尝试将 id 更改为一个类,这样所有表单都具有相同的类,例如 'chat_loc'

例如,将 JavaScript 更改为:

$(".chat_loc").on("submit", function() {
$(this).submit();
alert("submitted");
});

关于javascript - 我的其他表格没有提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45515417/

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