编辑现有评论的更好方法 我正在添加一些jQuery编辑/删除现有注释,而我现在乱七八糟,所以我想我会问一个更好的方法。
这是一个测试页面: 以下是测试登录:testing@problemio.com/测试 如果转到“注释”选项卡并添加注释,然后单击“编辑”,则用于添加注释的底部文本区域不会消失。但它应该是,因为我在它上面做了一个隐藏函数。这是我的密码: 我试图隐藏的形式:编辑现有评论的更好方法 我正在添加一些jQuery编辑/删除现有注释,而我现在乱七八糟,所以我想我会问一个更好的方法。,jquery,Jquery,这是一个测试页面: 以下是测试登录:testing@problemio.com/测试 如果转到“注释”选项卡并添加注释,然后单击“编辑”,则用于添加注释的底部文本区域不会消失。但它应该是,因为我在它上面做了一个隐藏函数。这是我的密码: 我试图隐藏的形式: <p class="comment_bottom_text"> <!-- Make a form for people to add comments --> <f
<p class="comment_bottom_text">
<!-- Make a form for people to add comments -->
<form id="add_comment" name="problem_comment_form" method="post">
<p>
<textarea name="problem_comment" cols=70 rows=6 id="problem_comment"></textarea>
</p>
<p>
<input type="hidden" id="comment_problem_id" name="problem_id" value="<?php echo $problem_id; ?>" />
<span class="error" id="add_message_error" style="display:none"> Please Enter Valid Data</span>
<span class="success" id="add_message_success" style="display:none"> Message Added Successfully!</span>
<input type="submit" class="button" value="Add Message"></input>
</p>
</form>
<p>
jQuery:
$('.edit_comment').live('click' , function()
{
// Showing the wait image
$("#loading").show();
var problem_id = $(this).attr("data-problem_id");
var problem_comment_id = $(this).attr("data-problem_comment_id");
var problem_comment_text = $(this).attr("data-problem_text");
// problem_comment_text_'.$problem_comment_id.'
var div_name = "problem_comment_text_" + problem_comment_id;
//alert ("div name: " + div_name );
//var dataString = 'problem_id='+ problem_id + '&problem_comment_id=' + problem_comment_id;
// Now validate the input
if( problem_id == '' || problem_comment_id == '' )
{
//$('#add_message_success').fadeIn(200).hide();
//$('#add_message_error').fadeOut(200).show();
}
else
{
// Check if the person is logged in.
// Now check if the person is logged in.
$.ajax({
type: "POST",
url: "/auth/check_login.php",
dataType: "json",
success: function(data)
{
$("#loading").hide();
//Maybe just switch up how the forms look like here.
// 1) close that piece of HTML
// Get the name of that piece of HTML.
// problem_comment_'.$problem_comment_id.'
// Close div named:
$("#" + div_name).hide(); // Works
// 2) Make an HTML form and display it in that piece of HTML
var new_comment_form = "<form id='add_comment' method='post'><p><textarea name='problem_comment' cols=60 rows=6 id='problem_comment'>" + problem_comment_text + "</textarea></p><p><input type='hidden' id='problem_id' name='problem_id' value='" + problem_id + "'><input type='hidden' id='problem_comment_id' value='" + problem_comment_id + "'></p><p><input type='submit' class='button' value='Edit Message'></input></p></form>";
// Now replace the current form with the crap I made above.
$("#" + div_name).html( new_comment_form ); // Works
$("#" + div_name).show( ); // Works
//alert("before hide");
// 3) Hide the other text area form.
$(".comment_bottom_text").hide(); // TODO - MAKE THIS WORK
//alert("after hide");
// 4) Give a cancel button to undo the whole thing I did here.
},
error: function(json) // Error for checking if user is logged in.
{
// Showing the wait image
$("#loading").hide();
$("#loginpopup").dialog();
return false;
}
});
}
return false;
});
问题是您试图隐藏的html元素不包含要隐藏的表单和按钮。 如果您查看web的代码,html就是这样的:
<p class="comment_bottom_text" style="display: none; ">
<!-- Make a form for people to add comments -->
</p>
然后你就有了表格。
这不是jquery的问题或错误您只是隐藏了一些您不想隐藏的内容,请检查将表单放入其中的代码或更改选择器看起来像是代码检查请求,这不是问题。@GolezTrol问题是如何使该div消失,而该div不会随着以下代码消失:$.comment\u bottom\u text.hide;//TODO-使其实际工作,样式=显示:无;我上面粘贴的html的一部分会在您单击编辑时显示,这样代码就可以完美地工作!!!请确保提出更具体的问题,并尝试更好地理解您的代码,以便其他人可以帮助您!sandino嗯,你知道我不是这么看代码的。我正在粘贴我在原始问题中的表单代码。您可以看到上面的标记已正确关闭,我不确定您在哪里看到显示:无;造型。我没有。我是用chrome浏览器看到的。我在编辑链接中单击后看到显示:无。您更新p定义的代码是您的代码中的内容,或者实际上是您在检查时在浏览器中看到的代码?。您可能遇到标记不匹配问题,请检查所有html标记是否已关闭,并使用工具验证标记