$(..).实时不是函数错误和复选框选中错误
$(...).live is not a function error and checkbox checked error
>我正在尝试从表单上使用的信息更新一些数据库行,但它有一些错误
这是有问题的代码:
var html = '';
$(document).ready(function(){
$(".save_btn").on('click', function() {
$('.response').each(function(){
//alert($(this).attr('id'));
var $no = no.checked;
var $yes = yes.checked;
alert($no);
alert($yes);
if ($no === 'no') {
html = $.ajax({
url: "response14.php?questionID=" + $(this).attr('id') + "&question=" + $(this).val() + "&check=2",
async: false
}).responseText;
}
if ($yes === 'yes') {
html = $.ajax({
//url: "response.php?questionID=" + $(this).attr('id') + "&response=" + $(this).val() + "&check=1",
url: "response14.php?questionID=" + $(this).attr('id') + "&question=" + escape($(this).val()) + "&check=1",
async: false
}).responseText;
}
});
alert(html);
location.reload();
});
})
回应14.php:
include("db_conn.php");
$sql = "update questions set approved = 1, question = ? where questionID = ?";
$qc = $pdo_conn->prepare($sql);
$qc->execute(array($_GET['question'], $_POST['questionID']));
echo 'saved';
带有按钮的代码:
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'> </div></td></tr>";
}
echo "</tbody></table>";
echo "<button type='button' class='save_btn' style='align:right'>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'>
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'>
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>
这是错误消息:
类型错误: $(...)。直播不是一个函数
$(".save_btn").live('click', function() {
有什么想法吗?
TypeError: $(...).live is not a function
$(".save_btn").live('click', function() {
上述错误是因为.live()
已从较新版本的jQuery
使用.on()
中弃用
$(".save_btn").on('click', function() {
-------------^^^----
-
.live 已弃用 .on
-
在哪里定义了"否"和"是"?如果是
<input type="radio" id="no" />
那么你需要$("#no")
但随后你测试价值,这没有意义。 -
显示一些HTML - 您似乎有多个响应,并且每个响应都有是/否?如果是这样,则需要命名才能找到它们。ID 必须是唯一的
你甚至不需要 Ajax:
$(function(){
$(".save_btn").on('click', function() {
var check = $("input[name=no]").is(":checked")?2:1;
// $(this).attr("id") next is the ID of the save button
location = "response14.php?questionID=" + $(this).attr('id') +
"&question=" + $(this).val() + "&check="+check;
});
});
认真使用
YES: <input type='checkbox' name='yes[]' value='yes'>
NO: <input type='checkbox' name='no[]' value='no'>
只需提交整个表格!!
如果你想要ajax(我从你的评论中看到你可能需要它,因为你想发布)试试这个
$(function(){
$(".save_btn").on('click', function(e) {
e.preventDefault() // in case you have a submit button
var check = $("input[name=no]").is(":checked")?2:1;
$.post("response14.php",{
"questionID":$(this).attr('id'),
"question":$(this).val(),
"check":check
},function(response) {
$("#someOutputDiv").html(response);
});
});
});
相关文章:
- jquery表单验证复选框错误显示
- Javascript错误,根据其他复选框的结果更新复选框/按钮
- Javascript复选框逻辑错误
- 复选框验证错误
- 量角器如果(复选框.isSelected())错误
- 检查所有选中的复选框是否具有值=正确,以及所有未选中的复选框的值=错误
- 未捕获的错误:语法错误,无法识别的表达式:输入:复选框[名称=ninja_forms_field_57[术语]]
- PHP 复选框邮件程序为每个错误
- 类型错误: 无法分配给只读属性“选中”复选框
- jQuery:计数选中的复选框 - 错误的计数
- 显示对话框时的错误复选框
- 我的JavaScript在复选框检查中有一些错误
- $(..).实时不是函数错误和复选框选中错误
- 语法错误,无法识别的表达式:[对象 HTMLDivElement]输入:复选框[名称=]:选中
- 保留Rails表单验证错误的复选框状态
- 即使选中复选框,也会出现错误
- Foundation复选框值错误
- 切换jquery读取值错误的复选框
- 如何绕过这个明显的 Webkit 复选框渲染错误
- Javascript不能在Chrome或IE9中工作-错误”;复选框未定义“;显示在FF JS控制台中