gpt4 book ai didi

javascript - object 对象和未定义的 GET 变量

转载 作者:行者123 更新时间:2023-11-30 12:56:34 25 4
gpt4 key购买 nike

这是我想要得到的 response14.php?questionID=1&question=yes&approved=1

这是我目前得到的 response14.php?questionID=[object%20Object]&question=undefined&approved=1

这是js文件:

$(document).ready(function(){
$(".save_btn").on('click', function() {
var check = $("input[name=no]").is(":checked")?2:1;
var questionID = $("textarea[id=questionID]").val();
var question = $("textarea[value=question]").val();
location = "response14.php?questionID=" +questionID + "&question=" +question + "&approved=" +check;

表格如下:

echo "<script src='viewsonly.js' type='text/javascript'> </script><br><center>";    
include("db_conn.php");

$qry_strings4 = "SELECT * FROM `Y new questions`";
$preps4 = $pdo_conn->prepare($qry_strings4);
$preps4->execute();
// $row = $preps4->fetch(PDO::FETCH_ASSOC);
//echo "$count";
echo "<table style='border:0px; background-color:lightgrey; width:75%'><thead style='border:0px;'><tr style='border:0px solid white; background-color:#153E7E; text-align:left; color:white; padding: 5; margin: 5;'><th style='border:1px white; padding: 5; margin: 5;'>Question</th><th style='border:1px white; padding: 5; margin: 5;'>Response</th></tr></thead><tbody>";
while ($row = $preps4->fetch(PDO::FETCH_ASSOC)) {
echo "<tr style='border:1px white; background-color:lightgrey; color:black; padding: 5; margin: 5;'><td style='border:1px white; vertical-align:top; padding: 5; margin: 5;'>{$row['starName']}</td>
<td style='border:1px white; padding: 5; margin: 5;'><div id='wrap'>
<textarea cols='85' rows='2' id='{$row['questionID']}' class='response textbox'>{$row['question']}</textarea>
YES: <input type='checkbox' name='yes[]' value='yes'>
NO: <input type='checkbox' name='no[]' value='no'>";
}
echo "</tbody></table>";
echo "<button type='button' class='save_btn'>Save All</button><br>";

呈现的 html:

 <td style='border:1px white; padding: 5; margin: 5;'><div id='wrap'>
<textarea cols='85' rows='2' id='3792' class='response textbox'>Hello C!!

Where can I send you fan mail? :)
I want your autograph and I'm from the Philippines :)

God bless Cooper!</textarea>
YES: <input type='checkbox' name='yes' value='yes'> &nbsp;&nbsp;&nbsp;
NO: <input type='checkbox' name='no' value='no'> </div></td></tr><tr style='border:1px white; background-color:lightgrey; color:black; padding: 5; margin: 5;'><td style='border:1px white; vertical-align:top; padding: 5; margin: 5;'>Gavin Casalegno</td>
<td style='border:1px white; padding: 5; margin: 5;'><div id='wrap'>
<textarea cols='85' rows='2' id='3793' class='response textbox'>What is your religion?
Do you believe in God?
How much you measure height?</textarea>
YES: <input type='checkbox' name='yes' value='yes'> &nbsp;&nbsp;&nbsp;
NO: <input type='checkbox' name='no' value='no'> </div></td></tr></tbody></table><button type='button' class='save_btn' style='align:right'>Save All</button><br>

关于如何解决这个问题的任何想法???

我刚刚按要求添加了呈现的 html

最佳答案

假设您有一个 ID 为 questionID 的唯一元素,在此分配中您应该在属性周围添加引号:

var questionID = $("textarea[id='questionID']").val();

即使你也可以简单地写

var questionID = $("#questionID").val();

在这里,您通过值属性定位文本区域,

var question = $("textarea[value=question]").val();

但 textareas 不提供值属性(请参阅 MDN 了解更多信息)


最后,如果你想执行一个 POST 请求,你需要使用 ajax。 (因为您使用的是 jQuery,请参阅 $.post 方法的文档)

关于javascript - object 对象和未定义的 GET 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18891478/

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